Created
October 10, 2016 07:06
-
-
Save nafis00141/ed3d662340b535bde1d6e6ae00a0771b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int par[5005]; | |
int n,e; | |
int fin(int x){ | |
if(par[x]==x) return x; | |
return par[x]=fin(par[x]); | |
} | |
void unio(int a, int b){ | |
a = fin(a); | |
b = fin(b); | |
if(a!=b) par[a]=b; | |
} | |
int main(){ | |
while(cin>>n>>e){ | |
if(n==0 && e==0) break; | |
char na[5005][105]; | |
int i; | |
for(i=0;i<n;i++){ | |
cin>>na[i]; | |
} | |
for(int j=0;j<i;j++) | |
par[j]=j; | |
while(e--){ | |
char a[40],b[40]; | |
cin>>a>>b; | |
int aa,bb; | |
for(int j=0;j<i;j++){ | |
if(strcmp(na[j],a)==0) aa = j; | |
if(strcmp(na[j],b)==0) bb= j; | |
} | |
unio(aa,bb); | |
} | |
for(int k=0;k<i;k++){ | |
int t = fin(k); | |
par[k]=t; | |
} | |
int m=0; | |
for(int j=0;j<i;j++){ | |
int cou=0; | |
for(int k=0;k<i;k++){ | |
if(par[j]==par[k]) { | |
cou++; | |
} | |
} | |
if(cou>m) m=cou; | |
} | |
cout<<m<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment