Thursday, May 14, 2015

UVa 10763 - Foreign Exchange

// UVa 10763 - Foreign Exchange

#include <iostream>
#include <map>
#include <vector>
using namespace std;

struct par {
	int a, b;
};

bool operator <(par x, par y) {
	return x.a < y.a || (x.a == y.a && x.b < y.b);
}

bool operator ==(par x, par y) {
	return x.a == y.a && x.b == y.b;
}

int main() {
	int n;
	while (cin >> n && n) {
		vector<par> v;
		map<par, int> count;
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b;
			if (a > b) {
				c = a;
				a = b;
				b = c;
				c = -1;
			} else
				c = 1;
			par p = { a, b };
			v.push_back(p);
			count[p] += c;
		}
		bool yes = true;
		for (int i = 0; i < n; i++)
			if (count[v[i]] != 0) {
				yes = false;
				break;
			}
		if (yes)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

No comments:

Post a Comment