Language: C++

#include <bits/stdc++.h>

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
int p[N], size[N];
PII bri[N];
vector<LL> res;

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++ ) scanf("%d%d", &bri[i].F, &bri[i].S);
	for (int i = 0; i <= n; i ++ ) p[i] = i, size[i] = 1;
	
	LL tot = (LL)n * (n - 1) / 2LL;
	for (int i = m - 1; i >= 0; i -- )
	{
		res.PB(tot);
		int pa = find(bri[i].F), pb = find(bri[i].S);
		
		if (pa != pb)
		{
			tot -= (LL)size[pa] * size[pb];
			size[pb] += size[pa];
			p[pa] = pb;
		}
	}
	
	reverse(res.begin(), res.end());
	for (auto u : res) printf("%lld\n", u);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:50: error: reference to 'size' is ambiguous
   31 |         for (int i = 0; i <= n; i ++ ) p[i] = i, size[i] = 1;
      |                                                  ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 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:17:11: note:                 'int size [100010]'
   17 | int p[N], size[N];
      |           ^~~~
a.cc:41:36: error: reference to 'size' is ambiguous
   41 |                         tot -= (LL)size[pa] * size[pb];
      |                                    ^~~~
/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:17:11: note:                 'int size [100010]'
   17 | int p[N], size[N];
      |           ^~~~
a.cc:41:47: error: reference to 'size' is ambiguous
   41 |                         tot -= (LL)size[pa] * size[pb];
      |                                               ^~~~
/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:17:11: note:                 'int size [100010]'
   17 | int p[N], size[N];
      |           ^~~~
a.cc:42:25: error: reference to 'size' is ambiguous
   42 |                         size[pb] += size[pa];
      |                         ^~~~
/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:17:11: note:                 'int size [100010]'
   17 | int p[N], size[N];
      |           ^~~~
a.cc:42:37: error: reference to 'size' is ambiguous
   42 |                         size[pb] += size[pa];
      |                                     ^~~~
/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:17:11: note:                 'int size [100010]'
   17 | int p[N], size[N];
      |           ^~~~