Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long lint;

class UnionFind{
public:
  UnionFind(int N);
  int root(int x);
  bool connect(int x, int y);
  lint size(int x);
private:
  vector<int> parent;
};

UnionFind::UnionFind(int N)
{
  parent = vector<lint>(N, -1);
}

lint UnionFind::root(int x)
{
  if(parent[x] < 0) return x;
  return parent[x] = root(parent[x]);
}

lint UnionFind::size(int x)
{
  return -parent[root(x)];
}

bool UnionFind::connect(int x, int y)
{
  x = root(x);
  y = root(y);
  if( x == y){
    return false;
  }
  if(size(x) < size(y))
    swap(x, y);

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

  return true;
}

int main(void)
{

  int N, M;
  cin >> N >> M;
  vector<int> qA(M);
  vector<int> qB(M);
  for(int i = 1; i <= M; i++){
    cin >> qA[M-i] >> qB[M-i];
    qA[M-i]--;
    qB[M-i]--;
  }
  lint size = N * (N - 1) / 2;
  vector<lint> ans;
  UnionFind uf(N);
  for(int i = 0; i < M; i++){
    ans.push_back(size);
    lint sizeA = uf.size(qA[i]);
    lint sizeB = uf.size(qB[i]);
    //cout << ans.back() << endl;
    if(uf.connect(qA[i], qB[i])){
      size = ans.back() - (lint)(sizeA * sizeB);
    }
  }
  for(int i = M-1; i >= 0; i--){
    cout << ans[i] << endl;
  }
}


Compiler output:
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:18:30: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'std::vector<long long int>')
   18 |   parent = vector<lint>(N, -1);
      |                              ^
In file included from /usr/include/c++/14/vector:72,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc: At global scope:
a.cc:21:6: error: no declaration matches 'lint UnionFind::root(int)'
   21 | lint UnionFind::root(int x)
      |      ^~~~~~~~~
a.cc:9:7: note: candidate is: 'int UnionFind::root(int)'
    9 |   int root(int x);
      |       ^~~~
a.cc:6:7: note: 'class UnionFind' defined here
    6 | class UnionFind{
      |       ^~~~~~~~~