-
Notifications
You must be signed in to change notification settings - Fork 0
/
10685.cpp
64 lines (62 loc) · 984 Bytes
/
10685.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
/*
10685 - Nature
*/
#include <bits/stdc++.h>
using namespace std;
int r[5005], p[5005];
int findp(int x)
{
return p[x] == x ? x : p[x] = findp(p[x]);
}
void joint(int x, int y)
{
x = findp(x);
y = findp(y);
if(x != y)
{
p[x] = y;
r[y] += r[x];
}
}
int main()
{
int C, R, i, j, k;
char cmd[105];
while(scanf("%d %d", &C, &R) == 2 && C)
{
map<string, int> M;
for(i = 0; i < C; i++)
{
scanf("%s", cmd), M[cmd] = i;
r[i] = 1, p[i] = i;
}
for(i = 0; i < R; i++)
{
cin>>cmd;
j = M[cmd];
cin>>cmd;
k = M[cmd];
joint(j, k);
}
int ans = 0;
for(i = 0; i < C; i++)
if(r[i] > ans)
ans = r[i];
cout<<ans<<endl;
}
return 0;
}
/*
Sample Input
5 2
caterpillar
bird
horse
elefant
herb
herb caterpillar
caterpillar bird
0 0
Sample Output
3
*/