Table of Contents
Edit on GithubCSES - Road Construction
Author: Oscar Garries
1#include <bits/stdc++.h>23using namespace std;45struct 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)]; }
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!