Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26204 Accepted Submission(s): 11751
c++
3 Alice Bob Smith John Alice Smith 5 a c c d d e b e a d 0
#include<bits/stdc++.h> using namespace std; map<string,int>m1,m2; int n,sum,loser; string str1,str2; int main() { while(scanf("%d",&n)&&n!=0) { sum=0; loser=0; m1.clear(); m2.clear(); while(n--) { cin>>str1>>str2; if(m1[str1]==0) { m1[str1]=1; sum++; } if(m1[str2]==0) { m1[str2]=1; sum++; } if(m2[str2]==0) { m2[str2]=1; loser++; } } if(sum-loser==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } }