Language: C++

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

template<typename T>
class dinamic_connectivity{
    using DC=dinamic_connectivity*;
	class euler_tour_tree{
		public:
		struct node;
		using np=shared_ptr<node>;
		using lint=long long;
		struct node{
			np ch[2]={nullptr,nullptr};
			np p=nullptr;
			int l,r,sz;
			T val=et,sum=et;
			node(){}
			node(int l,int r):l(l),r(r),sz(l==r){}
			bool is_root() {
				return !p;
			}
		};
		vector<hash_map<int,np>>ptr;
		np get_node(int l,int r){
			if(ptr[l].find(r)==ptr[l].end())ptr[l][r]=make_shared<node>(l,r);
			return ptr[l][r];
		}
		np root(np t){
			if(!t)return t;
			while(t->p)t=t->p;
			return t;
		}
		bool same(np s,np t){
			return root(s)==root(t);
		}
		np reroot(np t){
			auto s=split(t);
			return merge(s.second,s.first);
		}
		pair<np,np> split(np s){
			splay(s);
			np t=s->ch[0];
			if(t)t->p=nullptr;
			s->ch[0]=nullptr;
			return {t,update(s)};
		}
		pair<np,np> split2(np s){
			splay(s);
			np t=s->ch[0];
			np u=s->ch[1];
			if(t)t->p=nullptr;
			s->ch[0]=nullptr;
			if(u)u->p=nullptr;
			s->ch[1]=nullptr;
			return {t,u};
		}
		tuple<np,np,np> split(np s,np t){
			auto u=split2(s);
			if(same(u.first,t)){
				auto r=split2(t);
				return {r.first,r.second,u.second};
			}else{
				auto r=split2(t);
				return {u.first,r.first,r.second};
			}
		}
		template<typename First, typename... Rest>
		np merge(First s,Rest... t){
			return merge(s,merge(t...));
		}
		np merge(np s,np t){
			if(!s)return t;
			if(!t)return s;
			while(s->ch[1])s=s->ch[1];
			splay(s);
			s->ch[1]=t;
			if(t)t->p=s;
			return update(s);
		}
		int size(np t){return t?t->sz:0;}
		np update(np t){
			t->sum=et;
			if(t->ch[0])t->sum=fn(t->sum,t->ch[0]->sum);
			if(t->l==t->r)t->sum=fn(t->sum,t->val);
			if(t->ch[1])t->sum=fn(t->sum,t->ch[1]->sum);
			t->sz=size(t->ch[0])+(t->l==t->r)+size(t->ch[1]);
			return t;
		}
		void push(np t){
			//遅延評価予定
		}
		void rot(np t,bool b){
			np x=t->p,y=x->p;
			if((x->ch[1-b]=t->ch[b]))t->ch[b]->p=x;
			t->ch[b]=x,x->p=t;
			update(x);update(t);
			if((t->p=y)){
				if(y->ch[0]==x)y->ch[0]=t;
				if(y->ch[1]==x)y->ch[1]=t;
				update(y);
			}
		}
		void splay(np t){
			push(t);
			while(!t->is_root()){
				np q=t->p;
				if(q->is_root()){
					push(q), push(t);
					rot(t,q->ch[0]==t);
				}else{
					np r=q->p;
					push(r), push(q), push(t);
					bool b=r->ch[0]==q;
					if(q->ch[1-b]==t)rot(q,b),rot(t,b);
					else rot(t,1-b),rot(t,b);
				}
			}
		}
		void debug(np t){
			if(!t)return;
			debug(t->ch[0]);
			cerr<<t->l<<"-"<<t->r<<" ";
			debug(t->ch[1]);
		}
		constexpr static T et={};
		constexpr static T fn(T s,T t){
			return s;
		}
		public:
		euler_tour_tree(){}
		euler_tour_tree(int sz){
			ptr.resize(sz);
			for(int i=0;i<sz;i++)ptr[i][i]=new node(i,i);
		}
		int size(int s){
			np t=get_node(s,s);
			splay(t);
			return t->sz;
		}
		bool same(int s,int t){
            return root(get_node(s,s))==root(get_node(t,t));
        }
		void set_size(int sz){
			ptr.resize(sz);
			for(int i=0;i<sz;i++)ptr[i][i]=make_shared<node>(i,i);
		}
		void update(int s,T x){
			np t=get_node(s,s);
			splay(t);
			t->val=fn(t->val,x);
			update(t);
		}
		vector<pair<int,int>>edge_list(int s){
			np t=get_node(s,s);
			splay(t);
			vector<pair<int,int>>res;
			function<void(np)>dfs=[&](np t){
				if(!t)return;
				dfs(t->ch[0]);
				if(t->l<t->r)res.emplace_back(t->l,t->r);
				dfs(t->ch[1]);
			};
			dfs(t);
			return res;
		}
		vector<int>vertex_list(int s){
			np t=get_node(s,s);
			splay(t);
			vector<int>res;
			function<void(np)>dfs=[&](np t){
				if(!t)return;
				dfs(t->ch[0]);
				if(t->l==t->r)res.emplace_back(t->l);
				dfs(t->ch[1]);
			};
			dfs(t);
			return res;
		}
		bool link(int l,int r){
			if(same(l,r))return 0;
			merge(reroot(get_node(l,l)),get_node(l,r),reroot(get_node(r,r)),get_node(r,l));
			return 1;
		}
		bool cut(int l,int r){
			if(ptr[l].find(r)==ptr[l].end())return 0;
			np s,t,u;
			tie(s,t,u)=split(get_node(l,r),get_node(r,l));
			merge(s,u);
			ptr[l].erase(r);
			ptr[r].erase(l);
			return 1;
		}
		T get_sum(int p,int v){
			cut(p,v);
			np t=get_node(v,v);
			splay(t);
			T res=t->sum;
			link(p,v);
			return res;
		}
	};
	constexpr static int dep=20;
	euler_tour_tree ett[dep];
	vector<unordered_set<int>>edges[dep];
	int sz;
	public:
	dinamic_connectivity(int sz):sz(sz){
		for(int i=0;i<dep;i++){
			edges[i].resize(sz);
			ett[i].set_size(sz);
		}
	}
	bool link(int s,int t){
		if(s==t)return 0;
		if(ett[0].link(s,t))return 1;
		edges[0][s].insert(t);
		edges[0][t].insert(s);
		return 0;
	}
	bool same(int s,int t){
		return ett[0].same(s,t);
	}
	int size(int s){
		return ett[0].size(s);
	}
	vector<int>get_vertex(int s){
		return ett[0].vertex_list(s);
	}
	bool cut(int s,int t){
		if(s==t)return 0;
		for(int i=0;i<dep;i++){
			edges[i][s].erase(t);
			edges[i][t].erase(s);
		}
		for(int i=dep-2;i>=0;i--){
			if(ett[i].cut(s,t)){
				return !try_reconnect(s,t,i);
			}
		}
		return 0;
	}
	bool try_reconnect(int s,int t,int k){
		for(int i=k;i>=0;i--){
			ett[i].cut(s,t);
			if(ett[i].size(s)>ett[i].size(t))swap(s,t);
			auto edge_list=ett[i].edge_list(s);
			for(auto e:edge_list){
				ett[i+1].link(e.first,e.second);
			}
			auto vs=ett[i].vertex_list(s);
			vector<pair<int,int>>eraseList;
			for(auto x:vs)for(auto itr=edges[i][x].begin();itr!=edges[i][x].end();){
				auto y=*itr;
				itr=edges[i][x].erase(itr);
				edges[i][y].erase(x);
				if(ett[i].same(x,y)){
					edges[i+1][x].insert(y);
					edges[i+1][y].insert(x);
				}else{
					assert(ett[i].same(t,y));
					for(int j=0;j<i;j++){
						ett[j].cut(s,t);
					}
					ett[0].link(x,y);
					return 1;
				}
			}
		}
		return 0;
	}
};
 
int main(){
	lint n,m;
	cin>>n>>m;
	dinamic_connectivity<int>dc(n);
	vec s(m),t(m);
	rep(i,m){
		cin>>s[i]>>t[i];
		s[i]--;t[i]--;
		dc.link(s[i],t[i]);
	}
	lint ans=0;
	rep(i,m){
		if(dc.cut(s[i],t[i])){
			ans+=lint(dc.size(s[i]))*lint(dc.size(t[i]));
		}
		cout<<ans<<endl;
	}
}

Compiler output:
a.cc:51:19: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   51 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                   ^~~~
a.cc:51:33: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   51 | inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
      |                                 ^~~~
a.cc:52:19: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   52 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                   ^~~~
a.cc:52:33: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   52 | inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
      |                                 ^~~~
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:5:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = long long int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~