Language: C++

#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int gcd(int a, int b){return b ? gcd(b, a % b): a;}
void yes(){cout<<"Yes"<<endl;return;}
void no(){cout<<"No"<<endl;return;}

class UnionFind{
public:
    int *par, *rank, *size;
    UnionFind(int n){
        par = new int[n];
        rank = new int[n];
        size = new int[n];
        REP(i,0,n){
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {return par[x]==x? x: par[x] = root(par[x]);}
    int getsize(int x) {return size[root(x)];}
    bool connected(int x, int y) {return root(x)==root(y);}
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x==y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        }
        else {
            par[y] = x;
            size[x] += size[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
        return;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;

    UnionFind uf(n);
    int a = new int[m];
    int b = new int[m];
    ll ans = new ll[m];

    REP(i,0,m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    ll c = n * (n-1) / 2;
    for(int i=m-1; i>=0; i--){
        ans[i] = c;
        if(!uf.connected(a[i],b[i])){
            int size_a = uf.getsize(a[i]);
            int size_b = uf.getsize(b[i]);
            c -= size_a * size_b;
            uf.unite(a[i],b[i]);
        }
    }
    REP(i,0,m) {
        cout << ans[i] << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:22: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   67 |     int a = new int[m];
      |                      ^
      |                      |
      |                      int*
a.cc:68:22: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   68 |     int b = new int[m];
      |                      ^
      |                      |
      |                      int*
a.cc:69:22: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
   69 |     ll ans = new ll[m];
      |                      ^
      |                      |
      |                      ll* {aka long long int*}
a.cc:72:17: error: invalid types 'int[int]' for array subscript
   72 |         cin >> a[i] >> b[i];
      |                 ^
a.cc:72:25: error: invalid types 'int[int]' for array subscript
   72 |         cin >> a[i] >> b[i];
      |                         ^
a.cc:73:10: error: invalid types 'int[int]' for array subscript
   73 |         a[i]--; b[i]--;
      |          ^
a.cc:73:18: error: invalid types 'int[int]' for array subscript
   73 |         a[i]--; b[i]--;
      |                  ^
a.cc:78:12: error: invalid types 'll {aka long long int}[int]' for array subscript
   78 |         ans[i] = c;
      |            ^
a.cc:79:27: error: invalid types 'int[int]' for array subscript
   79 |         if(!uf.connected(a[i],b[i])){
      |                           ^
a.cc:79:32: error: invalid types 'int[int]' for array subscript
   79 |         if(!uf.connected(a[i],b[i])){
      |                                ^
a.cc:80:38: error: invalid types 'int[int]' for array subscript
   80 |             int size_a = uf.getsize(a[i]);
      |                                      ^
a.cc:81:38: error: invalid types 'int[int]' for array subscript
   81 |             int size_b = uf.getsize(b[i]);
      |                                      ^
a.cc:83:23: error: invalid types 'int[int]' for array subscript
   83 |             uf.unite(a[i],b[i]);
      |                       ^
a.cc:83:28: error: invalid types 'int[int]' for array subscript
   83 |             uf.unite(a[i],b[i]);
      |                            ^
a.cc:87:20: error: invalid types 'll {aka long long int}[int]' for array subscript
   87 |         cout << ans[i] << endl;
      |                    ^