-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10685.cpp
More file actions
62 lines (55 loc) · 936 Bytes
/
10685.cpp
File metadata and controls
62 lines (55 loc) · 936 Bytes
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
#include<bits/stdc++.h>
using namespace std;
long long int par[5005];
long long int group[5005];
map<string,long long int>nodes;
void makeSet(long long int x){
par[x] =x;
group[x] = 1;
}
long long int Find(long long int x){
if(par[x] == x){
return x;
}
par[x] = Find(par[x]);
return par[x];
}
void Union(long long int a,long long int b){
int x = Find(a);
int y = Find(b);
if(x != y){
par[x] = y;
group[y] += group[x];
}
}
int main(){
long long int v,e;
while(cin>>v>>e){
if(v == 0 && e == 0){
return 0;
}
int tmp = v;
nodes.clear();
long long int a = 1;
while(v--){
string s1;
cin>>s1;
if(nodes.find(s1) == nodes.end()){
nodes[s1] = a;
makeSet(a);
a++;
}
}
while(e--){
string s1,s2;
cin>>s1>>s2;
Union(nodes[s1],nodes[s2]);
}
long long int ans = 0;
for(int i =1;i<=tmp;i++){
if(ans < group[i]) ans = group[i];
}
cout<<ans<<endl;
}
return 0;
}