CSES - Road Construction
Author: Oscar Garries
Appears In
#include <bits/stdc++.h>using namespace std;struct DSU {vector<int> e;void init (int n) { e = vector<int> (n, -1); }int get (int x) { return (e[x] < 0 ? x : e[x] = get(e[x])); }bool sameSet (int x, int y) { return get(x) == get(y); }int size (int x) { return -e[get(x)]; }
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!