Language: C++

struct DSU {
  int n;
  vector<int> par, sz;
  vector<pair<int, int>> vx;
  int64_t ret = 0;
 
  DSU() = default;
 
  DSU(int n) : n(n) {
    par.resize(2 * n);
    iota(par.begin(), par.end(), 0);
    sz.assign(2 * n, 1);
    vx.resize(2 * n);
    for (int i = 0; i < n; ++i) {
      vx[i] = make_pair(1, 0);
    }
    for (int i = n; i < 2 * n; ++i) {
      vx[i] = make_pair(0, 1);
    }
  }
 
  int get(int x) {
    return x == par[x] ? x : get(par[x]);
  }
 
  int64_t calc(pair<int, int> p) {
    return (int64_t) p.first * p.second;
  }
 
  void unite(int x, int y) { // union-by-rank
    x = get(x), y = get(y);
    if (x == y) {
      hist.emplace_back(-1, -1);
      return;
    }
    if (sz[x] < sz[y]) swap(x, y);
    sz[x] += sz[y];
    par[y] = x;
    ret -= calc(vx[x]);
    ret -= calc(vx[y]);
    vx[x].first += vx[y].first;
    vx[x].second += vx[y].second;
    ret += calc(vx[x]);
  }
};

void solve(std::istream &in, std::ostream &out) {
  int n;
  uf = DSU(1 << 19);
  for (int i = 0, x, y; i < n; ++i) {
    in >> x >> y;
    uf.unite(x, y);
  }
  out << uf.ret << '\n';
}
 

Compiler output:
a.cc:3:3: error: 'vector' does not name a type
    3 |   vector<int> par, sz;
      |   ^~~~~~
a.cc:4:3: error: 'vector' does not name a type
    4 |   vector<pair<int, int>> vx;
      |   ^~~~~~
a.cc:5:3: error: 'int64_t' does not name a type
    5 |   int64_t ret = 0;
      |   ^~~~~~~
a.cc:1:1: note: 'int64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
  +++ |+#include <cstdint>
    1 | struct DSU {
a.cc:26:3: error: 'int64_t' does not name a type
   26 |   int64_t calc(pair<int, int> p) {
      |   ^~~~~~~
a.cc:26:3: note: 'int64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In constructor 'DSU::DSU(int)':
a.cc:10:5: error: 'par' was not declared in this scope
   10 |     par.resize(2 * n);
      |     ^~~
a.cc:11:5: error: 'iota' was not declared in this scope
   11 |     iota(par.begin(), par.end(), 0);
      |     ^~~~
a.cc:12:5: error: 'sz' was not declared in this scope
   12 |     sz.assign(2 * n, 1);
      |     ^~
a.cc:13:5: error: 'vx' was not declared in this scope
   13 |     vx.resize(2 * n);
      |     ^~
a.cc:15:15: error: 'make_pair' was not declared in this scope
   15 |       vx[i] = make_pair(1, 0);
      |               ^~~~~~~~~
a.cc:18:15: error: 'make_pair' was not declared in this scope
   18 |       vx[i] = make_pair(0, 1);
      |               ^~~~~~~~~
a.cc: In member function 'int DSU::get(int)':
a.cc:23:17: error: 'par' was not declared in this scope
   23 |     return x == par[x] ? x : get(par[x]);
      |                 ^~~
a.cc: In member function 'void DSU::unite(int, int)':
a.cc:33:7: error: 'hist' was not declared in this scope
   33 |       hist.emplace_back(-1, -1);
      |       ^~~~
a.cc:36:9: error: 'sz' was not declared in this scope
   36 |     if (sz[x] < sz[y]) swap(x, y);
      |         ^~
a.cc:36:24: error: 'swap' was not declared in this scope
   36 |     if (sz[x] < sz[y]) swap(x, y);
      |                        ^~~~
a.cc:37:5: error: 'sz' was not declared in this scope
   37 |     sz[x] += sz[y];
      |     ^~
a.cc:38:5: error: 'par' was not declared in this scope
   38 |     par[y] = x;
      |     ^~~
a.cc:39:5: error: 'ret' was not declared in this scope; did you mean 'get'?
   39 |     ret -= calc(vx[x]);
      |     ^~~
      |     get
a.cc:39:17: error: 'vx' was not declared in this scope; did you mean 'x'?
   39 |     ret -= calc(vx[x]);
      |                 ^~
      |                 x
a.cc:39:12: error: 'calc' was not declared in this scope
   39 |     ret -= calc(vx[x]);
      |            ^~~~
a.cc: At global scope:
a.cc:47:6: error: variable or field 'solve' declared void
   47 | void solve(std::istream &in, std::ostream &out) {
      |      ^~~~~
a.cc:47:17: error: 'istream' is not a member of 'std'
   47 | void solve(std::istream &in, std::ostream &out) {
      |                 ^~~~~~~
a.cc:1:1: note: 'std::istream' is defined in header '<istream>'; this is probably fixable by adding '#include <istream>'
  +++ |+#include <istream>
    1 | struct DSU {
a.cc:47:26: error: 'in' was not declared in this scope; did you mean 'int'?
   47 | void solve(std::istream &in, std::ostream &out) {
      |                          ^~
      |                          int
a.cc:47:35: error: 'ostream' is not a member of 'std'
   47 | void solve(std::istream &in, std::ostream &out) {
      |                                   ^~~~~~~
a.cc:1:1: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | struct DSU {
a.cc:47:44: error: 'out' was not declared in this scope
   47 | void solve(std::istream &in, std::ostream &out) {
      |                                            ^~~