-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
38 lines (27 loc) · 801 Bytes
/
template.cpp
File metadata and controls
38 lines (27 loc) · 801 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
#include <bits/stdc++.h>
using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;
const ll INF = (ll)1e11;
template<typename T>
struct UnionFind {
std::vector<T> parent;
std::vector<T> rank;
UnionFind(T n) : parent(n), rank(n,0) { std::iota(parent.begin(), parent.end(), 0); }
T find(T x) { return (parent[x] == x ? x : (parent[x] = find(parent[x]))); }
void unite(T x, T y) {
x = find(x); y = find(y);
if (x == y) return;
if (rank[x] < rank[y]) parent[x] = y;
else {
parent[y] = x;
if (rank[x] == rank[y]) ++rank[x];
}
}
bool inSame(T x, T y) { return find(x) == find(y); }
};
using namespace std;
int main() {
ios::sync_with_stdio(false);
return 0;
}