Union Find - YessineJallouli/Competitive-Programming GitHub Wiki
#include <bits/stdc++.h>
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;
const int mx = 2e5+7;
int par[mx];
int Find(int node) {
if (par[node] == node)
return node;
return par[node] = Find(par[node]);
}
void Union(int n1, int n2) {
int a1 = Find(n1);
int a2 = Find(n2);
if (a1 == a2)
return;
par[a1] = a2;
}
int main() {
SaveTime
for (int i = 0; i < mx; i++)
par[i] = i;
}
Resources :
http://www.france-ioi.org/algo/task.php?idChapter=540&idTask=836
Problems :
https://codeforces.com/group/Gb7ARsml3C/contest/338746/problem/G