-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10608.cpp
More file actions
38 lines (27 loc) · 763 Bytes
/
10608.cpp
File metadata and controls
38 lines (27 loc) · 763 Bytes
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
#include <iostream>
using namespace std;
int friends[30001], sizes[30001];
int findSet(int a) { while(a != friends[a]) a = friends[a]; return a; }
void unionSet(int a, int b) {
int sa = findSet(a), sb = findSet(b);
if (sa != sb) friends[sa] = sb;
}
int main () {
int tc; cin >> tc;
while (tc--) {
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) friends[i] = i, sizes[i] = 0;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b; a--; b--;
unionSet(a, b);
}
for (int i = 0; i < n; i++) friends[i] = findSet(i);
int largest = 0;
for (int i = 0; i < n; i++) {
sizes[friends[i]]++;
largest = max(largest, sizes[friends[i]]);
}
cout << ((m) ? largest : 0) << endl;
}
return 0;
}