Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;


//----------------------------------------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e5+1;//                                                               |
//----------------------------------------------------------------------------------

vl parent(N,0);
vl size(N,0);

void make_set(ll x){
    size[x]=1;
    parent[x]=x;
}


ll find_parent(ll x)
{   
    vl tmp;
    
    while(x!=parent[x])
    {
        tmp.eb(x);
        x=parent[x];
    }
    
    for(auto i:tmp) parent[i]=x;
    
    return x;
}


void union_set(ll x, ll y)
{
    ll a=find_parent(x);
    ll b=find_parent(y);
    
    if(a!=b){
        if(size[a]>=size[b]){
            parent[b]=a;
            size[a]+=size[b];
        }
        else{
            parent[a]=b;
            size[b]+=size[a];
        }
    }
}

ll get_size(ll x)
{
    return size[find_parent(x)];
    
}

//main func
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	ll n,m;cin>>n>>m;
	vp v(m);
	
	for(auto &i:v) cin>>i.ff>>i.ss;
	
	ll zero_parents=n;
	
	vl ans;
	ans.eb(((zero_parents)*(zero_parents-1))/2);
	
	for(int i=m-1;i>0;i--){
	    ll a=v[i].ff,b=v[i].ss;
	    if(parent[a]==0) {make_set(a);zero_parents--;}
	    if(parent[b]==0) {make_set(b);zero_parents--;}
	    
	    union_set(a,b);
	    
	    ll c=get_size(a);
	    ll val=c*(n-c)+((zero_parents)*(zero_parents-1))/2;
	    //cout<<val<<"\n";
	    ans.eb(val);
	}
	
	reverse(all(ans));
	
	for(auto i:ans) cout<<i<<"\n";
	
	return 0;
}

Compiler output:
a.cc: In function 'void make_set(ll)':
a.cc:35:5: error: reference to 'size' is ambiguous
   35 |     size[x]=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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc: In function 'void union_set(ll, ll)':
a.cc:62:12: error: reference to 'size' is ambiguous
   62 |         if(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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc:62:21: error: reference to 'size' is ambiguous
   62 |         if(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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc:64:13: error: reference to 'size' is ambiguous
   64 |             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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc:64:22: error: reference to 'size' is ambiguous
   64 |             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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc:68:13: error: reference to 'size' is ambiguous
   68 |             size[b]+=size[a];
      |             ^~~~
/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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc:68:22: error: reference to 'size' is ambiguous
   68 |             size[b]+=size[a];
      |                      ^~~~
/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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~
a.cc: In function 'll get_size(ll)':
a.cc:75:12: error: reference to 'size' is ambiguous
   75 |     return size[find_parent(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:32:4: note:                 'vl size'
   32 | vl size(N,0);
      |    ^~~~