-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoj1450.cpp
78 lines (72 loc) · 1.22 KB
/
oj1450.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
struct Player{
char name[100];
} player[2000];
vector<int> edge[2000];
queue<int> q;
int inDegree[2000];
int size;
int ctop(const char *a){
for(int i=0;i<size;i++)
if(strcmp(player[i].name,a)==0)
return i;
strcpy(player[size].name,a);
return size++;
}
void init(){
for(int i=0;i<2000;i++){
strcpy(player[i].name,"\0");
edge[i].clear();
inDegree[i]=0;
}
while(!q.empty()) q.pop();
size=0;
return;
}
bool ouput(int n){
int ret=0;
for(int i=0;i<n;i++){
if(inDegree[i]==0){
q.push(i);
break;
}
}
while(!q.empty()){
int now=q.front();
q.pop();
ret++;
for(int i=0;i<edge[now].size();i++){
int tmp=edge[now][i];
if(--inDegree[tmp]==0)
q.push(tmp);
}
}
if(ret==n)
return true;
else
return false;
}
int main(){
int n;
while(scanf("%d",&n)&&n){
init();
char sa[100],sb[100];
for(int i=0;i<n;i++){
int a,b;
scanf("%s%s",sa,sb);
a=ctop(sa);
b=ctop(sb);
edge[a].push_back(b);
inDegree[b]++;
}
if(ouput(size))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}