Language: C++

#include <iostream>
using namespace std;
#define MAX 100001
#define ll long long
int par[MAX],size[MAX];

int root(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x] = root(par[x]);
	}
}

void unite(int x,int y){
	x = root(x);
	y = root(y);
	if(x!=y){
		par[x] = y;
		size[x] += size[y];
		size[y] = size[x];
	}
}

int main(){
	ll ans[MAX]
	int in[MAX][2],n,m;
	cin >> n >> m;
	ans[0] = (n*n-n)/2;		//橋の数０のときの不便さ
	for(int i=1;i<=n;i++){
		par[i] = i;
		size[i] = 1;
	}
	for(int i=0;i<m;i++)	cin >> in[i][0] >> in[i][1];
	for(int i=1;i<=m;i++){
		int a,b;
		a = in[m-i][0];
		b = in[m-i][1];
		if(root(a)!=root(b)){
			ans[i] = ans[i-1] - size[a]*size[b];
			unite(a,b);
		}
	}
	for(int i=m-1;i>=0;i--){
		cout << ans[i] << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void unite(int, int)':
a.cc:20:17: error: reference to 'size' is ambiguous
   20 |                 size[x] += size[y];
      |                 ^~~~
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:1:
/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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc:20:28: error: reference to 'size' is ambiguous
   20 |                 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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc:21:17: error: reference to 'size' is ambiguous
   21 |                 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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc:21:27: error: reference to 'size' is ambiguous
   21 |                 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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc: In function 'int main()':
a.cc:27:9: error: expected initializer before 'int'
   27 |         int in[MAX][2],n,m;
      |         ^~~
a.cc:28:16: error: 'n' was not declared in this scope
   28 |         cin >> n >> m;
      |                ^
a.cc:28:21: error: 'm' was not declared in this scope; did you mean 'tm'?
   28 |         cin >> n >> m;
      |                     ^
      |                     tm
a.cc:29:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   29 |         ans[0] = (n*n-n)/2;             //橋の数０のときの不便さ
      |         ^~~
      |         abs
a.cc:32:17: error: reference to 'size' is ambiguous
   32 |                 size[i] = 1;
      |                 ^~~~
/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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc:34:40: error: 'in' was not declared in this scope; did you mean 'i'?
   34 |         for(int i=0;i<m;i++)    cin >> in[i][0] >> in[i][1];
      |                                        ^~
      |                                        i
a.cc:37:21: error: 'in' was not declared in this scope; did you mean 'i'?
   37 |                 a = in[m-i][0];
      |                     ^~
      |                     i
a.cc:40:45: error: reference to 'size' is ambiguous
   40 |                         ans[i] = ans[i-1] - size[a]*size[b];
      |                                             ^~~~
/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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~
a.cc:40:53: error: reference to 'size' is ambiguous
   40 |                         ans[i] = ans[i-1] - size[a]*size[b];
      |                                                     ^~~~
/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:5:14: note:                 'int size [100001]'
    5 | int par[MAX],size[MAX];
      |              ^~~~