-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11060.cpp
44 lines (41 loc) · 897 Bytes
/
P11060.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
int main() {
int N, M, a1, a2, indegree[100];
string s, b1, b2;
bool done[100];
for(int cas = 1; cin >> N; ++cas) {
map<string,int> m; // name -> index
vector<string> names(N);
vector<vector<int> > out(N);
FORI(N) {
cin >> names[i];
m[names[i]] = i;
}
memset(indegree, 0, sizeof(indegree));
memset(done, false, sizeof(done));
cin >> M;
FORI(M) {
cin >> b1 >> b2;
a1 = m[b1];
a2 = m[b2];
out[a1].push_back(a2);
++indegree[a2];
}
cout << "Case #" << cas << ": Dilbert should drink beverages in this order:";
int printed = 0;
while(printed < N) {
FORI(N) {
if(done[i] || indegree[i] > 0)
continue;
cout << " " << names[i];
done[i] = true;
++printed;
FORIT(vector<int>, out[i]) {
--indegree[*it];
}
break;
}
}
cout << "." << endl << endl;
}
return 0;
}