代码:
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> p; // A-->B (A想去B)
int main()
{
int n;
while(cin>>n && n)
{
int a,b,cnt=n; //cnt表示目前n个需求
map<p,int> m; //记录是否存在xx想去xx
for(int i=0;i<n;i++)
{
cin>>a>>b;
if(!m[{b,a}]) m[{a,b}]++; //如果不存在对方想来这边的,记录下这边的情况
else m[{b,a}]--,cnt-=2; //如果存在对方想来这边,可以配对,减去一次对面到这边的情况,总需求减2
}
if(!cnt) cout<<"YES"<<endl; //总需求为0,都配对了
else cout<<"NO"<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/weixin_45260385/article/details/108184282
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论