Last active
February 17, 2017 12:17
-
-
Save dada8397/40e89ce2443afdeac0d42596e73d97d7 to your computer and use it in GitHub Desktop.
UVa 10685 - Nature
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 <cstdio> | |
#include <map> | |
#include <cstring> | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
int set[5010]; | |
int num[5010]; | |
int Find(int x) { | |
if(x == set[x]) return x; | |
return set[x] = Find(set[x]); | |
} | |
void Union(int x, int y) { | |
x = Find(x); | |
y = Find(y); | |
if(x != y) { | |
set[x] = y; | |
num[y] += num[x]; | |
} | |
} | |
int main(void) { | |
int C, R; | |
map<string, int> m; | |
while(cin >> C >> R) { | |
if(C == 0 && R == 0) break; | |
string A, B; | |
for(int i=0; i<C; i++) { | |
cin >> A; | |
m[A] = i; | |
} | |
for(int i=0; i<=C; i++) { | |
set[i] = i; | |
num[i] = 1; | |
} | |
for(int i=0; i<R; i++) { | |
cin >> A >> B; | |
Union(m[A], m[B]); | |
} | |
int maxnum = 0; | |
for(int i=0; i<C; i++) { | |
if(num[i] > maxnum) maxnum = num[i]; | |
} | |
cout << maxnum << endl; | |
m.clear(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment