Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11444 Accepted Submission(s):
5299
#include<stdio.h> #include<string.h> #include<queue> #define MAX 1100 using namespace std; char s1[30],s2[30]; char str[MAX][30]; int ru[MAX]; int num,n; void getmap() { int i,j,q,p; num=1; while(n--) { scanf("%s%s",s1,s2); q=p=-1; for(i=1;i<num;i++) { if(strcmp(str[i],s1)==0) q=i; if(strcmp(str[i],s2)==0) p=i; if(q!=-1&&p!=-1) break; } if(q==-1) { q=num++; strcpy(str[q],s1); } if(p==-1) { p=num++; strcpy(str[p],s2); } ru[p]++; } } void mix() { int i,j,sum=0; for(i=1;i<num;i++) { if(ru[i]==0) sum++; if(sum>1) break; } if(sum==1) printf("Yes\n"); else printf("No\n"); } int main() { while(scanf("%d",&n),n) { memset(ru,0,sizeof(ru)); getmap(); mix(); } return 0; }
原文:http://www.cnblogs.com/tonghao/p/4722238.html