-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunionfind.cpp
More file actions
65 lines (44 loc) · 995 Bytes
/
unionfind.cpp
File metadata and controls
65 lines (44 loc) · 995 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
#define MAINRET(x) in##x
#define what_is(x) cout << #x << " is " << x << endl;
#define LL long long
void solve();
MAINRET(t) main(void) {
std::cin.tie(nullptr);
std::cin.sync_with_stdio(false);
solve();
}
constexpr int INF = (int)1e9 + 100;
constexpr LL LINF = LLONG_MAX / 2;
constexpr int NINF = -INF;
constexpr LL MX = 3 * 1e5;
constexpr int MD = (int)1e9 + 7;
struct Uf {
vector<int> grp, sz;
Uf(int n = MX) {
grp = vector<int>(n);
sz = vector<int>(n, 1);
for (int i = 0; i < n; i++) grp[i] = i;
}
int Find(int a) {
return a == grp[a] ? a : grp[a] = Find(grp[a]);
}
void Union(int a, int b) {
a = Find(a);
b = Find(b);
if (a != b) {
if (sz[a] < sz[b]) {
swap(a, b);
}
grp[b] = a;
sz[a] += sz[b];
}
}
};
int n, m, k;
void solve() {
cin >> n;
}
/*
*/