-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriends_UVA10608.cpp
68 lines (54 loc) · 1.16 KB
/
Friends_UVA10608.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
#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;
ifstream fin("Friends_UVA10608.in");
ofstream fout("Friends_UVA10608.out");
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()
{
int testCaseTotal; fin >> testCaseTotal;
for (int t = 1; t <= testCaseTotal; ++t)
{
int n, m; fin >> 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; fin >> 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]]);
}
fout << ans << '\n';
}
return 0;
}