Language: C++

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

class UnionFind2{
private:
    vector<int> _root;
    vector<int> _rank;
    
public:
    UnionFind(int n){
        _root.resize(n);
        _rank.resize(n);
        for(int i=0; i<n; i++){
            _root[i] = i;
            _rank[i] = 0;
        }
    }
    
    int root(int x){
        if(_root[x] == x)
            return x;
        return _root[x] = root(_root[x]);
    }
    
    bool unite(int x, int y){
        if(is_same_group(x, y))
            return false;
        
        x = root(x);
        y = root(y);
        
        if(_rank[x] < _rank[y]){
            _root[x] = y;
        }else{
            _root[y] = x;
            if(_rank[x] == _rank[y])
                _rank[x]++;
        }
        return true;
    }
    
    bool is_same_group(int x, int y){
        return root(x) == root(y);
    }
};

class UnionFind1 {
    vector<int> par;
    int cnt;
public:
    UnionFind(int size_) : par(size_, -1), cnt(size_) { }
    void unite(int x, int y){
        if ((x = find(x)) != (y = find(y))) {
            if (par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    bool same(int x, int y){ return find(x) == find(y); }
    int find(int x){ return par[x] < 0 ? x : par[x] = find(par[x]); }
    int size(int x){ return -par[find(x)]; }
    int size(){ return cnt; }
};

int main(){
    ll N, M; cin >> N >> M;
    UnionFind U1(N);
    UnionFind U2(N);
    vector<PII> E(M);
    for(int i=0; i<M; i++){
        ll a, b; cin >> a >> b;
        a--; b--;
        E[i] = PII(a, b);
    }
    
    ll X = (N-1)*N/2;
    vector<ll> G(N);
    vector<ll> S(N, 1);
    vector<ll> Ans;
    
    for(ll i=M-1; i>=0; i--){
        Ans.push_back(X);
        ll a = E[i].first;
        ll b = E[i].second;
        ll dec = U.size(a)*U.size(b);
        X = max(0LL, X-dec);
    }
    
    for(int i=M-1; i>=0; i--)
        cout << Ans[i] << endl;
 
    return 0;
}


Compiler output:
a.cc:32:5: error: ISO C++ forbids declaration of 'UnionFind' with no type [-fpermissive]
   32 |     UnionFind(int n){
      |     ^~~~~~~~~
a.cc: In member function 'int UnionFind2::UnionFind(int)':
a.cc:39:5: warning: no return statement in function returning non-void [-Wreturn-type]
   39 |     }
      |     ^
a.cc: At global scope:
a.cc:73:5: error: ISO C++ forbids declaration of 'UnionFind' with no type [-fpermissive]
   73 |     UnionFind(int size_) : par(size_, -1), cnt(size_) { }
      |     ^~~~~~~~~
a.cc: In member function 'int UnionFind1::UnionFind(int)':
a.cc:73:28: error: only constructors take member initializers
   73 |     UnionFind(int size_) : par(size_, -1), cnt(size_) { }
      |                            ^~~
a.cc:73:57: warning: no return statement in function returning non-void [-Wreturn-type]
   73 |     UnionFind(int size_) : par(size_, -1), cnt(size_) { }
      |                                                         ^
a.cc: In function 'int main()':
a.cc:88:5: error: 'UnionFind' was not declared in this scope; did you mean 'UnionFind2'?
   88 |     UnionFind U1(N);
      |     ^~~~~~~~~
      |     UnionFind2
a.cc:89:14: error: expected ';' before 'U2'
   89 |     UnionFind U2(N);
      |              ^~~
      |              ;
a.cc:106:18: error: 'U' was not declared in this scope
  106 |         ll dec = U.size(a)*U.size(b);
      |                  ^