Language: C++

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
#define MAX_N 10000

int par[MAX_N];
int size[MAX_N];

struct edge{
	int start;
	int to;
};

void init(){
	rep(i,MAX_N){
		par[i] = i;
		size[i] = 1;
	}
}

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

bool isSame(int i,int j){
	i = root(par[i]);
	j = root(par[j]);
	return i == j;
}

void unite(int i, int j){
	i = root(i);
	j = root(j);
	if(i == j) return;
	if(size[i] > size[j]){
		int temp = i;
		i = j;
		j = temp;
	}
	par[i] = j;
	size[j] += size[i];
}

ll siz(int i){
	return size[root(i)];
}

int main()
{
	int N,M;
	cin>>N>>M;
	vector<edge> edgeList;
	vector<int> ans(M+1);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		struct edge e;
		e.start = x;
		e.to = y;
		edgeList.push_back(e);
	}
	init();
	ans[M] = N*(N-1)/2;
	for(int i = M-1; i >= 0; i--){
		if( isSame(edgeList[i].start,edgeList[i].to) == true){
			ans[i] = ans[i+1];
			unite(edgeList[i].start,edgeList[i].to);
		}else{
			ans[i] = ans[i+1] - siz(edgeList[i].start)*siz(edgeList[i].to);
			unite(edgeList[i].start,edgeList[i].to);
		}
	}
	rep(i,M){
		cout<<ans[i+1]<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'void init()':
a.cc:28:17: error: reference to 'size' is ambiguous
   28 |                 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:2:
/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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:48:12: error: reference to 'size' is ambiguous
   48 |         if(size[i] > size[j]){
      |            ^~~~
/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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~
a.cc:48:22: error: reference to 'size' is ambiguous
   48 |         if(size[i] > size[j]){
      |                      ^~~~
/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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~
a.cc:54:9: error: reference to 'size' is ambiguous
   54 |         size[j] += size[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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~
a.cc:54:20: error: reference to 'size' is ambiguous
   54 |         size[j] += size[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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~
a.cc: In function 'll siz(int)':
a.cc:58:16: error: reference to 'size' is ambiguous
   58 |         return size[root(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:18:5: note:                 'int size [10000]'
   18 | int size[MAX_N];
      |     ^~~~