2013年8月24日

UVa 10763 - Foreign Exchange

#include <cstdio>
#include <map>
using namespace std;

int main() {
  int n;
  while (scanf("%d", &n) && n) {
    map<int, int> now, to;
    while (n--) {
      int a, b;
      scanf("%d%d", &a, &b);
      now[a]++;
      to[b]++;
    }
    bool ok = (now.size() == to.size());
    for (map<int, int>::iterator it = now.begin(); ok && it != now.end(); it++) {
      ok = (it->second == to[it->first]);
    }
    puts(ok ? "YES" : "NO");
  }
  return 0;
}

沒有留言:

張貼留言