-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriends_UVA10608OJ.cpp
70 lines (55 loc) · 1.16 KB
/
Friends_UVA10608OJ.cpp
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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
int _find(int u, vector<int> & p)
{
if (p[u] == u)
{
return u;
}
else
{
int ans = _find(p[u], p);
p[u] = ans;
return ans;
}
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int testCaseTotal; cin >> testCaseTotal;
for (int t = 1; t <= testCaseTotal; ++t)
{
int n, m; cin >> n >> m;
vector<int> p(n + 1), g(n + 1, 0);
for (int i = 1; i <= n; ++i)
{
p[i] = i;
}
for (int c = 1; c <= m; ++c)
{
int u, v; cin >> u >> v;
p[_find(v, p)] = p[_find(u, p)];
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
++g[_find(i, p)];
ans = max(ans, g[p[i]]);
}
cout << ans << '\n';
}
cout.flush();
return 0;
}