Language: C++

#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <limits.h>
#include <iostream>
#define REP(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
const int inf=1<<30;
const int INF=INT_MAX;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const int d[]={0,1,0,-1,0};//int nx=x+d[i],ny=y+d[i+1]

int par[100001];
int rank[100001];

void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rank[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rank[x] < rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
}
bool same(int x, int y) {
  return find(x) == find(y);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  int fu[100001], a[100001], b[100001];
  cin >> n >> m;
  init(n);
  REP(i, m) {
    cin >> a[i] >> b[i];
  }
  fu[m] = n * (n - 1) / 2;
  for(int i = m - 1; i >= 0; --i) {
    if(same(a[i], b[i])) {
      fu[i] = fu[i + 1];
    } else {
      fu[i] = fu[i + 1] - rank[par[a[i]]] * rank[par[a[i]]];
    }
    unite(a[i], b[i]);
  }

  for(int i = 1; i <= m; ++i) {
    cout << fu[i] << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:28:5: error: reference to 'rank' is ambiguous
   28 |     rank[i] = 1;
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:42:7: error: reference to 'rank' is ambiguous
   42 |   if (rank[x] < rank[y]) {
      |       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc:42:17: error: reference to 'rank' is ambiguous
   42 |   if (rank[x] < rank[y]) {
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc:46:9: error: reference to 'rank' is ambiguous
   46 |     if (rank[x] == rank[y]) rank[x]++;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc:46:20: error: reference to 'rank' is ambiguous
   46 |     if (rank[x] == rank[y]) rank[x]++;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc:46:29: error: reference to 'rank' is ambiguous
   46 |     if (rank[x] == rank[y]) rank[x]++;
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:68:27: error: reference to 'rank' is ambiguous
   68 |       fu[i] = fu[i + 1] - rank[par[a[i]]] * rank[par[a[i]]];
      |                           ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~
a.cc:68:45: error: reference to 'rank' is ambiguous
   68 |       fu[i] = fu[i + 1] - rank[par[a[i]]] * rank[par[a[i]]];
      |                                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:23:5: note:                 'int rank [100001]'
   23 | int rank[100001];
      |     ^~~~