-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10685 - Nature
74 lines (65 loc) · 1.18 KB
/
10685 - Nature
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
#include <bits/stdc++.h>
using namespace std;
int arr[5005] , parent[5005];
map <string , int> mp;
void Set_all (int n)
{
for(int i = 0; i < n; i++)
{
parent[i] = i;
arr[i] = 1;
}
}
int make_friend (int n)
{
if(parent[n] == n)
return n;
return parent[n] = make_friend(parent[n]);
}
void Union_find (int a , int b)
{
int x , y;
x = make_friend(a);
y = make_friend(b);
if(x == y) return;
else
{
parent[x] = y;
arr[y] += arr[x];
}
}
int main()
{
int n , query;
ios_base :: sync_with_stdio(0);
cin.tie(0);
while(cin >> n >> query)
{
if(n == 0 and query == 0)
break;
Set_all(n);
string s;
for(int i = 0; i < n; i++)
{
cin >> s;
mp[s] = i;
}
string s1, s2;
while(query--)
{
cin >> s1 >> s2;
int p , q;
p = mp[s1];
q = mp[s2];
Union_find(p , q);
}
int maxs = 0;
for(int i = 0; i < n; i++)
{
if(arr[i] > maxs)
maxs = arr[i];
}
cout<<maxs << endl;
mp.clear();
}
}