-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy path10685.cc
45 lines (45 loc) · 839 Bytes
/
10685.cc
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
// https://uva.onlinejudge.org/external/106/10685.pdf
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using msi=unordered_map<string,int>;
int main(){
int n,m,u,v;
while(1){
cin>>n>>m;
if(!n)break;
vvi g(n);
int k=0;
msi d;
for(int i=0;i<n;i++){
string s;
cin>>s;
d[s]=k++;
}
for(int i=0;i<m;i++){
string s,t;
cin>>s>>t;
u=d[s];v=d[t];
g[u].push_back(v);
g[v].push_back(u);
}
vi c(n);
function<void(int,int)>dfs=[&](int u,int k){
c[u]=k;
for(int v:g[u])
if(!c[v])
dfs(v,k);
};
k=1;
for(int i=0;i<n;i++)
if(!c[i])
dfs(i,k++);
vi s(k);
for(int i=0;i<n;i++)
s[c[i]]++;
int M=0;
for(int x:s)M=max(M,x);
cout<<M<<endl;
}
}