USACO Gold 2018 January - Mootube

Author: Óscar Garries

Official Analysis

C++

C++ Implementation

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)]; }

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!

Give Us Feedback on USACO Gold 2018 January - Mootube!