10763:Foreign Exchange
version 1(100ms):
#include<cstdio>
#include<map>
#include<set>
using namespace std;
int n;
int main(){
while(scanf("%d",&n) && n){
map<int,int>ori,tar;
set<int>sch;
int a,b;
for(int i = 0;i < n;i++){
scanf("%d %d",&a,&b);
if(!ori.count(a)) ori[a] = 0;
if(!tar.count(b)) tar[b] = 0;
ori[a]++,tar[b]++;
sch.insert(a);
}
int mark = 1;
for(set<int>::iterator it = sch.begin();it != sch.end() && mark;it++){
if(!tar.count(*it) || tar[*it] != ori[*it]) mark = 0;
}
printf("%s\n",mark ? "YES" : "NO");
}
return 0;
}
Email:JingwangLi@outlook.com