/*
按照题意的理解,满足条件,需要a->b和b->a学生数量一样,
因此设计map,int>dic来记录a->b学生数量,如果有b->a的,那么就a->b数量减1,
最后字典中每个元素的value都是0的时候,即可满足交换条件,否则不满足。
本题学习的地方是如何构造满足自己需要的hash函数,进而设计自定义的unordered_map
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct pair_hash {
template <class T1, class T2>
std::size_t operator () (const std::pair<T1,T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
// Mainly for demonstration purposes, i.e. works but is overly simple
// In the real world, use sth. like boost.hash_combine
return h1 ^ h2;
}
};
using namespace std;
using Vote = pair<int, int>;
using Unordered_map = unordered_map<Vote, int, pair_hash>;
int main()
{
int n,a,b;
while(scanf("%d",&n)!=EOF&&n){
Unordered_map dic;
for(int i=0;i
scanf("%d%d",&a,&b);
auto p=make_pair(a,b),q=make_pair(b,a);
if(dic.find(p)!=dic.end())++dic[p];
else if(dic.find(q)!=dic.end())--dic[q];
else dic[p]=1;
}
int flag=1;
for(auto &p:dic)if(p.second!=0){flag=0;break;}
printf("%s\n",flag?"YES":"NO");
}
return 0;
}