-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSU.sublime-snippet
53 lines (47 loc) · 925 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
45
46
47
48
49
50
51
52
53
<snippet>
<content><![CDATA[
class DSU
{
public:
int N;
vector<int>v;
vector<int>sz;
DSU(int N)
{
this->N = N;
v.resize(N);
sz.resize(N, 1);
for (int i = 0; i < N; i++)
{
v[i] = i;
}
};
int find(int x)
{
if (v[x] == x)
return x;
else
return v[x] = find(v[x]);
}
int size(int x)
{
return sz[find(x)];
}
void addEdge(int x, int y)
{
if (find(x) == find(y))
return;
else
{
sz[find(y)] += sz[find(x)];
v[find(x)] = find(y);
}
}
// ~DSU();
};
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>DSU</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>