-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSU.cpp
More file actions
51 lines (41 loc) · 846 Bytes
/
DSU.cpp
File metadata and controls
51 lines (41 loc) · 846 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
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n';
#define yes cout << "Yes\n";
#define no cout << "No\n";
const int N = 1000 + 9, mod = 1e9 + 7, inf = 1e18;
int parent[N];
int sz[N];
void make_set(int n){
for(int i = 1; i <= n; i++){
parent[i] = i;
sz[i] = 1;
}
}
int find_set(int u){
if(parent[u]==u) return u;
return parent[u] = find_set(parent[u]);
}
void union_set(int u, int v){
int a = find_set(u);
int b = find_set(v);
if(sz[a]<sz[b]) swap(a, b);
if(a!=b){
parent[b] = a;
sz[a] += sz[b];
}
}
void solve() {
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}