Language: C++

#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<pair<int, int> > v;

struct dsu {
  vi pset;
  vi size;
  int numsets;
  dsu(int n) {
    numsets = n;
    pset.resize(n);
    size.resize(n);
    forn(i, n) pset[i] = i;
    forn(i, n) size[i] = 1;
  }
  int find_set(int i) {
    return pset[i] == i ? i : pset[i] = find_set(pset[i]);
  }
  void unify(int i, int j) {
    int a = find_set(i), b = find_set(j);
    if (a == b) return;
    numsets--;
    if (size[a] < size[b]) {
      pset[a] = b;
      size[b] += size[a];
    } else {
      pset[b] = a;
      size[a] += size[b];
    }
  }
  bool same_set(int i, int j) {
    return find_set(i) == find_set(j);
  }
  int size_set(int i) {
    return size[find_set(i)];
  }
};

int main() {
	cin >> n >> m;
  	for (int i = 0; i < m; i++) {
      	int a, b;
      	cin >> a >> b;
      	a--; b--;
    	v.push_back(make_pair(a, b)); 
    }
  	int ans[m];
  	dsu d(n);
  	int cur = n * (n - 1) / 2;
  	for (int i = m - 1; i >= 0; i--) {
      	bool b = d.same_set(v[i].first, v[i].second);
      	if (!b) {
         	int a = d.size_set(v[i].first);
          	int b = d.size_set(v[i].second);
          	cur -= a * b;
        }
     	d.unify(v[i].first, v[i].second);
      	ans[i] = cur;
    }
  	for (int i = 0; i < m; i++) {
     	cout << ans[i] << endl; 
    }
}

Compiler output:
a.cc:8:3: error: 'vi' does not name a type; did you mean 'void'?
    8 |   vi pset;
      |   ^~
      |   void
a.cc:9:3: error: 'vi' does not name a type; did you mean 'void'?
    9 |   vi size;
      |   ^~
      |   void
a.cc: In constructor 'dsu::dsu(int)':
a.cc:13:5: error: 'pset' was not declared in this scope
   13 |     pset.resize(n);
      |     ^~~~
a.cc:14:10: error: overloaded function with no contextual type information
   14 |     size.resize(n);
      |          ^~~~~~
a.cc:15:10: error: 'i' was not declared in this scope
   15 |     forn(i, n) pset[i] = i;
      |          ^
a.cc:15:5: error: 'forn' was not declared in this scope; did you mean 'fork'?
   15 |     forn(i, n) pset[i] = i;
      |     ^~~~
      |     fork
a.cc: In member function 'int dsu::find_set(int)':
a.cc:19:12: error: 'pset' was not declared in this scope
   19 |     return pset[i] == i ? i : pset[i] = find_set(pset[i]);
      |            ^~~~
a.cc: In member function 'void dsu::unify(int, int)':
a.cc:25:13: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   25 |     if (size[a] < size[b]) {
      |             ^
a.cc:25:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   25 |     if (size[a] < size[b]) {
      |                       ^
a.cc:26:7: error: 'pset' was not declared in this scope
   26 |       pset[a] = b;
      |       ^~~~
a.cc:27:11: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   27 |       size[b] += size[a];
      |           ^
a.cc:27:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   27 |       size[b] += size[a];
      |                      ^
a.cc:29:7: error: 'pset' was not declared in this scope
   29 |       pset[b] = a;
      |       ^~~~
a.cc:30:11: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   30 |       size[a] += size[b];
      |           ^
a.cc:30:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   30 |       size[a] += size[b];
      |                      ^
a.cc: In member function 'int dsu::size_set(int)':
a.cc:37:16: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   37 |     return size[find_set(i)];
      |                ^