Language: C++

#include<iostream>
#include<vector>
using namespace std;
class UnionFind {
  //子供は親を、おやは-(グループのサイズ)
  vector<int> Parent;
public:
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
  }
  int get(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = get(Parent[A]);
  }
  int size(int A) {
    return -Parent[get(A)];
  }
  bool connect (int A, int B) {
    A = get(A);
    B = get(B);
    if (A == B) return false; // 親が一緒なら何もしない
    if (size(A) > size(B)) {
      Parent[A] = -(size(A) + size(B));
      Parent[B] = A;
      return true;
    }
    Parent[B] = -(size(A) + size(B));
    Parent[A] = B;
    return true;
  }
}
      
int main () {
  int N, M;
  cin >> N >> M;
  long long max = N * (N - 1) / 2;
  vector<int>A(M);
  vector<int>B(M);
  for (int i = 0; i < M; i ++) cin >> A[i] >> B[i];
  UnionFind jun(N);
  vector<long long>ans(M);
  ans [M - 1] = max;
  for (int i = M - 1; i > 0; i --) {
    ans[i - 1] = ans[i] - size(A[i]) * size(B[i]);
    if (!jun.connect(A[i], B[i])) {
      ans[i - 1] = ans[i];
    }
  }
  for (int i = 0; i < M; i ++) cout << ans[i] << endl;
}


Compiler output:
a.cc:31:2: error: expected ';' after class definition
   31 | }
      |  ^
      |  ;
a.cc: In function 'int main()':
a.cc:44:31: error: no matching function for call to 'size(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   44 |     ans[i - 1] = ans[i] - 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:44:31:   required from here
   44 |     ans[i - 1] = ans[i] - 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:44:31: note:   mismatched types 'const _Tp [_Nm]' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   44 |     ans[i - 1] = ans[i] - size(A[i]) * size(B[i]);
      |                           ~~~~^~~~~~
a.cc:44:44: error: no matching function for call to 'size(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   44 |     ans[i - 1] = ans[i] - 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:44:44:   required from here
   44 |     ans[i - 1] = ans[i] - 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:44:44: note:   mismatched types 'const _Tp [_Nm]' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   44 |     ans[i - 1] = ans[i] - size(A[i]) * size(B[i]);
      |                                        ~~~~^~~~~~