-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path142.cpp
More file actions
59 lines (57 loc) · 1.04 KB
/
Copy path142.cpp
File metadata and controls
59 lines (57 loc) · 1.04 KB
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
#include <iostream>
#include <cstring>
using namespace std;
class Set {
private:
int n;
int* relation;
public:
Set(int amount) {
n = amount;
relation = new int[n+1];
for (int i = 1; i <= n; i++) {
relation[i] = i;
}
}
int Find(int x) {
int p = relation[x];
while (p != relation[p]) {
p = relation[p];
}
relation[x] = p;
return relation[x];
}
void Union(int i, int j) {
if (Find(i) != Find(j)) {
relation[relation[i]] = relation[relation[j]];
}
}
};
int main() {
int caseNum;
cin >> caseNum;
for (int c = 0; c < caseNum; c++) {
int n, r;
cin >> n >> r;
Set* friends = new Set(n);
for (int i = 0; i < r; i++) {
int x, y;
cin >> x >> y;
friends->Union(x, y);
}
int *relation = new int[n+1];
int max = 0;
for (int j = 1; j <= n; j++) {
relation[j] = 0;
}
for (int i = 1; i <= n; i++) {
relation[friends->Find(i)]++;
max = max > relation[friends->Find(i)] ? max : relation[friends->Find(i)];
}
cout << max << endl;
delete[] relation;
delete friends;
}
system("pause");
return 0;
}