Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++) 
typedef long long ll;
using namespace std;

class UnionFind {
public:
    vector<int> parent;  //親ノード
    vector<int> Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(int n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(int n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    int root(int x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {

        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }

    // xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    int size(int x) {
        return Siz[root(x)];
    }
};
 
int main() {
    int n, m;
    cin >> n >> m;
 
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    UnionFind Uni(n);
 
    vector<ll> ans(m);
    ans[m-1] = (ll)n*(n-1)/2;
    for(int i = m-1; i >= 1; i--) {
 
        if(Uni.same(a[i], b[i])) {
            ans[i-1] = ans[i];
        }
        else {
            ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
            Uni.unite(a[i], b[i]);
        }
    }
 
    rep(i, m) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:91:41: error: no matching function for call to 'size(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                     ~~~~^~~~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&) [with _Container = int]':
a.cc:91:41:   required from here
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                     ~~~~^~~~~~
/usr/include/c++/14/bits/range_access.h:263:24: error: request for member 'size' in '__cont', which is of non-class type 'const int'
  263 |     -> decltype(__cont.size())
      |                 ~~~~~~~^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   template argument deduction/substitution failed:
a.cc:91:41: note:   mismatched types 'const _Tp [_Nm]' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                     ~~~~^~~~~~
a.cc:91:54: error: no matching function for call to 'size(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                                  ~~~~^~~~~~
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/range_access.h: In substitution of 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&) [with _Container = int]':
a.cc:91:54:   required from here
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                                  ~~~~^~~~~~
/usr/include/c++/14/bits/range_access.h:263:24: error: request for member 'size' in '__cont', which is of non-class type 'const int'
  263 |     -> decltype(__cont.size())
      |                 ~~~~~~~^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   template argument deduction/substitution failed:
a.cc:91:54: note:   mismatched types 'const _Tp [_Nm]' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   91 |             ans[i-1] = ans[i] - (ll)size(a[i]) * size(b[i]);
      |                                                  ~~~~^~~~~~