Language: C++

#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p, old;
	vector<int> chg;
	UF() {}
	UF(int n) : p(n, -1),old(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		chg.clear();
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		chg.push_back(a); chg.push_back(b);
		
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	vector<VI> g(m, VI(2));
	rep(i,m) cin >> g[i][0] >>g[i][1];
	vector<ll> ans(m);
	ll sp = (ll)n*(n-1)/2;
	ans[m-1] = sp;
	UF uf(m);
	auto old = uf.p;
	repr(i, m-1, 1){
		uf.unite(g[i][0]-1, g[i][1]-1);
		ll sk=0;
		//rep(i,n) if(uf.root(i)) sk += (ll)uf.size(i) * (uf.size(i) -1) /2;
		for(auto x :uf.chg){
			if(uf.p[x] < 0) sp -= (ll)uf.size(x) * (uf.size(x) -1) /2;
			if(old[x] >0)   sp += (ll)old[x] * (old[x]-1) /2;
			old[x] = uf.size(x);
		}
		ans[i-1] = min(0, sp);
		//for(auto x :uf.p) printf("%d, ",x); puts("");
		//for(auto x :old) printf("%d, ",x); puts("old");
	}
	
	for(auto x :ans){
		cout << x <<"\n";
	}
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:57:31: error: no matching function for call to 'min(int, ll&)'
   57 |                 ans[i-1] = min(0, sp);
      |                            ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:57:31: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   57 |                 ans[i-1] = min(0, sp);
      |                            ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:57:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   57 |                 ans[i-1] = min(0, sp);
      |                            ~~~^~~~~~~