Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11580 Accepted Submission(s): 5370
3 Alice Bob Smith John Alice Smith 5 a c c d d e b e a d 0
Yes No
#include<stdio.h> #include<string.h> char win[1010][1010], lose[1010][1010]; int indegree[1010]; void topo(int n){ int i, j, cnt = 0; memset(indegree, 0, sizeof(indegree)); for(i = 0; i < n; ++i){ for(j = 0; j < n; ++j){ if(strcmp(win[i], lose[j]) == 0){ indegree[i] = 1; } if(!indegree[i] && !indegree[j] && i < j){ if(strcmp(win[i], win[j]) == 0) indegree[j] = 1; } } } for(i = 0; i < n; ++i){ if(!indegree[i]) cnt++; } if(cnt == 1) printf("Yes\n"); else printf("No\n"); } int main(){ int n; while(~scanf("%d", &n), n){ int i; for(i = 0; i < n; ++i){ scanf("%s%s", win[i], lose[i]); } topo(n); } return 0; }