CSES - Road Construction

Author: Oscar Garries

Table of Contents


Edit on Github
1#include <bits/stdc++.h>
2
3using namespace std;
4
5struct DSU {
6 vector<int> e;
7 void init (int n) { e = vector<int> (n, -1); }
8 int get (int x) { return (e[x] < 0 ? x : e[x] = get(e[x])); }
9 bool sameSet (int x, int y) { return get(x) == get(y); }
10 int size (int x) { return -e[get(x)]; }

Give Us Feedback on CSES - Road Construction!

Join the Discussion!

Feel free to voice your thoughts in the comments section.