-
Notifications
You must be signed in to change notification settings - Fork 7
/
LightOj 1003.cpp
56 lines (53 loc) · 1.28 KB
/
LightOj 1003.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
#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
bool comp(int a,int b)
{
if(a>b) return true;
return false;
}
int main()
{
int i,j,k,p,count,t,tcase=1,m,n;
string a,b;
scanf("%d",&t);
while(t--){
scanf("%d",&m);
vector<int>list[10005];
map<string,int>mp;
k=1;
vector<int>dp(10005);
for(i=1;i<=m;i++){
cin>>a>>b;
if(mp[a]==0) mp[a]=k++;
if(mp[b]==0) mp[b]=k++;
//cout<<a<<" "<<mp[a]<<" "<<b<<" "<<mp[b]<<"\n";
list[mp[a]].push_back(mp[b]);
dp[mp[b]]++;
}
count=0;
for(i=1;i<k;i++){
for(j=1;j<k;j++){
if(dp[j]==0){
dp[j]=-1;
count++;
//printf("Test\n");
for(p=0;p<list[j].size();p++){
dp[list[j][p]]--;
//printf("%d %d\n",list[j][p],dp[list[j][p]]);
}
}
}
}
//sort(dp.begin(),dp.end(),comp);
printf("Case %d: ",tcase++);
if(count==(k-1)) printf("Yes\n");
else printf("No\n");
}
return 0;
}