-
Notifications
You must be signed in to change notification settings - Fork 10
/
dsu.sublime-snippet
44 lines (40 loc) · 934 Bytes
/
dsu.sublime-snippet
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
<snippet>
<content><![CDATA[
template <typename T>
class dsu {
public:
vector<T> p;
vector<T> rank;
int n;
dsu(int _n) : n(_n) {
p.resize(n);
rank.resize(n);
iota(p.begin(), p.end(), 0);
fill(rank.begin(), rank.end() , 1);
}
inline T get(T x) {
return (x == p[x] ? x : (p[x] = get(p[x])));
}
inline bool unite(T x, T y) {
T px = get(x);
T py = get(y);
if (px != py) {
if(rank[px] == rank[py]){
p[py] = px;
rank[px]++;
} else if(rank[px] < rank[py]){
p[px] = py;
} else {
p[py] = px;
}
return true;
}
return false;
}
};
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>disjoint sets</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.cpp , source.cxx , source.cc , source.c , source.c++ </scope>
</snippet>