Language: C++

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
#define MAX_N 10000000
int par[MAX_N];
int rank[MAX_N];
int ren[100006];
void init(int n)
{
	rep(i,n)
	{
		par[i]=i;
		rank[i]=0;
		ren[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;
		ren[y]+=ren[x];
	}
	else
	{
		par[y]=x;
		ren[x]+=ren[y];
		if(rank[x]==rank[y])rank[x]++;
	}
}
bool same(int x,int y)
{
	return find(x)==find(y);
}
int findren(int x)
{
	x=find(x);
	return ren[x];
}
int n,m;
int a[100006];
int b[100006];
int ans[100006];
int fans;
int aa,bb;
int main()
{
	cin>>n>>m;
	rep(i,m)cin>>a[i]>>b[i];
	//rep(i,n)ren[i]=1;
	fans=n*(n-1)/2;
	ans[m-1]=fans;
	init(n);
	for(int i=m-1;i>=1;i--)
	{
		aa=a[i];
		bb=b[i];
		if(same(aa,bb))
		{
			//cout<<"j"<<i<<endl;
			ans[i-1]=ans[i];
		}
		else
		{
			//cout<<"i"<<i<<endl;
			ans[i-1]=ans[i]-findren(aa)*findren(bb);
			//cout<<"find(aa)"<<findren(aa)<<"find(bb)"<<findren(bb)<<endl;
			unite(aa,bb);
		}
	}
	rep(i,m)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:30:17: error: reference to 'rank' is ambiguous
   30 |                 rank[i]=0;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:43:12: error: reference to 'rank' is ambiguous
   43 |         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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~
a.cc:43:20: error: reference to 'rank' is ambiguous
   43 |         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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~
a.cc:52:20: error: reference to 'rank' is ambiguous
   52 |                 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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~
a.cc:52:29: error: reference to 'rank' is ambiguous
   52 |                 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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~
a.cc:52:37: error: reference to 'rank' is ambiguous
   52 |                 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 [10000000]'
   23 | int rank[MAX_N];
      |     ^~~~