Language: C++

#include<iostream>
#include<vector>
using namespace std;
class UnionFind {
  //子供は親を、おやは-(グループのサイズ)
  vector<int> Parent;
public:
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
  }
  void 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:50:2: error: expected '}' at end of input
   50 | }
      |  ^
a.cc:4:17: note: to match this '{'
    4 | class UnionFind {
      |                 ^
a.cc: In member function 'void UnionFind::get(int)':
a.cc:12:31: error: return-statement with a value, in function returning 'void' [-fpermissive]
   12 |     if (Parent[A] < 0) return A;
      |                               ^
a.cc:13:27: error: void value not ignored as it ought to be
   13 |     return Parent[A] = get(Parent[A]);
      |                        ~~~^~~~~~~~~~~
a.cc: In member function 'int UnionFind::size(int)':
a.cc:16:19: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'void')
   16 |     return -Parent[get(A)];
      |                   ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from 'void' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from 'void' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc: In member function 'bool UnionFind::connect(int, int)':
a.cc:19:12: error: void value not ignored as it ought to be
   19 |     A = get(A);
      |         ~~~^~~
a.cc:20:12: error: void value not ignored as it ought to be
   20 |     B = get(B);
      |         ~~~^~~
a.cc: In member function 'int UnionFind::main()':
a.cc:50:1: warning: no return statement in function returning non-void [-Wreturn-type]
   50 | }
      | ^
a.cc: At global scope:
a.cc:50:2: error: expected unqualified-id at end of input
   50 | }
      |  ^