-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheatSheet.cpp
More file actions
94 lines (79 loc) · 1.79 KB
/
Copy pathCheatSheet.cpp
File metadata and controls
94 lines (79 loc) · 1.79 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <functional>
#include <queue>
#include <bitset>
#include <sstream>
#include <set>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// //AUTHOR: Hugo Garcia
// //PURPOSE: Competitive programming template
//======================================================================================================================
#define FOR(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define pb push_back
#define mp make_pair
#define lld I64d
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
//======================================================================================================================
class UnionFind
{
private:
vi p, rank;
public:
UnionFind(ll N)
{
rank.assign(N, 0);
p.assign(N, 0);
for (ll i = 0; i < N; ++i)
{
p[i] = i;
}
}
ll findSet(ll i)
{
return (p[i] == i) ? i : (p[i] = findSet(p[i]));
}
bool isSameSet(ll i, ll j)
{
return findSet(i) == findSet(j);
}
void unionSet(ll i, ll j)
{
if (!isSameSet(i, j))
{
ll x = findSet(i), y = findSet(j);
if (rank[x] > rank[y])
{
p[y] = x;
}
else
{
p[x] = y;
if (rank[x] == rank[y])
{
rank[y]++;
}
}
}
}
};
//----------------------------------------------------------------------------------------------------------------------
int main()
{
return 0;
}
//======================================================================================================================