Language: C++

#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int par[100100];
int rank[100100];
int size[100100];

void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		rank[i]=0;
		size[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;
	
	size[x]=size[x]+size[y];
	size[y]=size[x];
	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);
}

ll n,m;
ll a[100100],b[100100];
ll ans[100100];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	ans[m-1]=(n*n-1)/2;
	init(100100);
	for(int i=m-2;i>=0;i--){
		ans[i]=size[find(a[i])]*size[find(b[i])];
		unite(a[i],b[i]);
	}
	for(int i=0;i<m;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:34:17: error: reference to 'rank' is ambiguous
   34 |                 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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc:35:17: error: reference to 'size' is ambiguous
   35 |                 size[i]=1;
      |                 ^~~~
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:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:52:9: error: reference to 'size' is ambiguous
   52 |         size[x]=size[x]+size[y];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:52:17: error: reference to 'size' is ambiguous
   52 |         size[x]=size[x]+size[y];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:52:25: error: reference to 'size' is ambiguous
   52 |         size[x]=size[x]+size[y];
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:53:9: error: reference to 'size' is ambiguous
   53 |         size[y]=size[x];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:53:17: error: reference to 'size' is ambiguous
   53 |         size[y]=size[x];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:54:12: error: reference to 'rank' is ambiguous
   54 |         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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc:54:20: error: reference to 'rank' is ambiguous
   54 |         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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc:58:20: error: reference to 'rank' is ambiguous
   58 |                 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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc:58:29: error: reference to 'rank' is ambiguous
   58 |                 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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc:58:37: error: reference to 'rank' is ambiguous
   58 |                 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:28:5: note:                 'int rank [100100]'
   28 | int rank[100100];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:76:24: error: reference to 'size' is ambiguous
   76 |                 ans[i]=size[find(a[i])]*size[find(b[i])];
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~
a.cc:76:41: error: reference to 'size' is ambiguous
   76 |                 ans[i]=size[find(a[i])]*size[find(b[i])];
      |                                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: '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:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:29:5: note:                 'int size [100100]'
   29 | int size[100100];
      |     ^~~~