Language: C++

//q087.cpp
//Sun Sep  6 17:01:43 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

//Union-Find木
int par[1000000]; //親。1個上の親でしか無いことに注意。グループの根はfindで呼び出す。
int size[1000000]; //木のサイズ

//n要素で初期化
void init(int n){
	for (int i=0;i<n;i++){
		par[i] = i;
		size[i] = 1;
	}
}

//木の根（親）を見つける。再帰することで、グループの根まで辿る。
int find (int x){
	if (par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合の併合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	} 
	if (size[x]>size[y]){
		par[y] = x;
		size[x] += size[y];
	}else{
		par[x] = y;
		size[y] += size[x];
	}
}

//xとyが同じグループに属するか判定
bool same(int x, int y){
	return find(x) == find(y);
}


int main(){
	ll n,m;
	cin >> n >> m;

	vector<ll> a(m,0);
	vector<ll> b(m,0);
	rep(i,m) cin >> a[i] >> b[i];

	init(n);

	vector<ll> ans(m,0);
	ll cur = n*(n-1)/2;
	for(ll i=m-1;i>=0;i--){
		ans[i]=cur;
		if (!same(a[i],b[i])){
			cur -= size[find(a[i])]*size[find(b[i])];
		}
		unite(a[i],b[i]);
	}

	rep(i,m){
		cout << ans[i] << endl;
	}
//	printf("%.4f\n",ans);
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:30:17: error: reference to 'size' is ambiguous
   30 |                 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,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:50:13: error: reference to 'size' is ambiguous
   50 |         if (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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:50:21: error: reference to 'size' is ambiguous
   50 |         if (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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:52:17: error: reference to 'size' is ambiguous
   52 |                 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:52:28: error: reference to 'size' is ambiguous
   52 |                 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:55:17: error: reference to 'size' is ambiguous
   55 |                 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:55:28: error: reference to 'size' is ambiguous
   55 |                 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc: In function 'int main()':
a.cc:80:32: error: reference to 'size' is ambiguous
   80 |                         cur -= 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~
a.cc:80:49: error: reference to 'size' is ambiguous
   80 |                         cur -= 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:24:5: note:                 'int size [1000000]'
   24 | int size[1000000]; //木のサイズ
      |     ^~~~