Language: C++

#include<iostream>
using namespace std;
class UnionFind{
   public:
      vector<int> parent;
      
      UnionFind(int N)
      {
         parent = vector<int>(N, -1);
      }
      int root(int A)
      {
         if(parent[A] < 0) return A;
         return parent[A] = root(patent[A]);
      }
      int size(int A)
      {
         return -parent[root(A)];
      }
      bool connect(int A, int B)
      {
         A = root(A);
         B = root(B);
         if(A == B)
         {
            return  false;
         }
         if(size(A) < size(B))
            swap(A, B);
         parent[A] += parent[B];
         parent[B] = A;
         return true;
      }
}
int main()
{
   int N, M;
   cin >> N >> M;
   vector<int> A(M), B(M);
   for(int i = 0; i < M; i++)
   {
      cin >> A[i] >> B[i];
      A[i]--;
      B[i]--;
   }
   vector<long long> ans(M);
   ans[M-1] = (long long) N*(N-1)/2;
   UnionFind Uni(N);
   for(int i = M - 1; i >= 1; i--)
   {
      if(Uni.root(A[i]) != Uni.root(B[i]))
      {
         ans[i-1] = ans[i] - (long long)Uni.size(A[i])*Uni.size(B[i]);
         Uni.connect(A[i], B[i]);
      }
      else
      {
         ans[i-1] = ans[i];
      }
   }
   for(int i = 0; i < M; i++)
   {
      cout << ans[i] << endl;
   }
}


int main()
{
   return 0;
}


Compiler output:
a.cc:5:7: error: 'vector' does not name a type
    5 |       vector<int> parent;
      |       ^~~~~~
a.cc:34:2: error: expected ';' after class definition
   34 | }
      |  ^
      |  ;
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:9:10: error: 'parent' was not declared in this scope
    9 |          parent = vector<int>(N, -1);
      |          ^~~~~~
a.cc:9:19: error: 'vector' was not declared in this scope
    9 |          parent = vector<int>(N, -1);
      |                   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:9:26: error: expected primary-expression before 'int'
    9 |          parent = vector<int>(N, -1);
      |                          ^~~
a.cc: In member function 'int UnionFind::root(int)':
a.cc:13:13: error: 'parent' was not declared in this scope
   13 |          if(parent[A] < 0) return A;
      |             ^~~~~~
a.cc:14:17: error: 'parent' was not declared in this scope
   14 |          return parent[A] = root(patent[A]);
      |                 ^~~~~~
a.cc:14:34: error: 'patent' was not declared in this scope; did you mean 'putenv'?
   14 |          return parent[A] = root(patent[A]);
      |                                  ^~~~~~
      |                                  putenv
a.cc: In member function 'int UnionFind::size(int)':
a.cc:18:18: error: 'parent' was not declared in this scope
   18 |          return -parent[root(A)];
      |                  ^~~~~~
a.cc: In member function 'bool UnionFind::connect(int, int)':
a.cc:30:10: error: 'parent' was not declared in this scope
   30 |          parent[A] += parent[B];
      |          ^~~~~~
a.cc: In function 'int main()':
a.cc:39:4: error: 'vector' was not declared in this scope
   39 |    vector<int> A(M), B(M);
      |    ^~~~~~
a.cc:39:4: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:39:11: error: expected primary-expression before 'int'
   39 |    vector<int> A(M), B(M);
      |           ^~~
a.cc:42:14: error: 'A' was not declared in this scope
   42 |       cin >> A[i] >> B[i];
      |              ^
a.cc:42:22: error: 'B' was not declared in this scope
   42 |       cin >> A[i] >> B[i];
      |                      ^
a.cc:46:11: error: expected primary-expression before 'long'
   46 |    vector<long long> ans(M);
      |           ^~~~
a.cc:47:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |    ans[M-1] = (long long) N*(N-1)/2;
      |    ^~~
      |    abs
a.cc:51:19: error: 'A' was not declared in this scope
   51 |       if(Uni.root(A[i]) != Uni.root(B[i]))
      |                   ^
a.cc:51:37: error: 'B' was not declared in this scope
   51 |       if(Uni.root(A[i]) != Uni.root(B[i]))
      |                                     ^
a.cc: At global scope:
a.cc:68:5: error: redefinition of 'int main()'
   68 | int main()
      |     ^~~~
a.cc:35:5: note: 'int main()' previously defined here
   35 | int main()
      |     ^~~~