criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
#define lson(o<<1)
#define rson(o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
struct UnionFind
{
	vector<int> par;
	vector<int> sizes;
	UnionFind(int N):par(N),sizes(N,1)
	{
		for(int i=0;i<N;i++)
		{
			par[i]=i;
		}
	}
	int root(int x)
	{
		if(par[x]==x)
		{
			return x;
		}
		else
		{
			return par[x]=root(par[x]);
		}
	}
	int size(int x)
	{
		return sizes[root(x)];
	}
	void unite(int x,int y)
	{
		int rx=root(x);
		int ry=root(y);
		if(rx==ry)
		{
			return;
		}
		par[ry]=rx;
		sizes[rx] += sizes[ry];
	}
	bool same(int x,int y)
	{
		int rx=root(x);
		int ry=root(y);
		return rx==ry;
	}
};

int main()
{
    long long N,M;
    cin >> N >> M;
    vector<pair<int,int>> AB(M);
    for(int i=0;i<M;i++)
    {
        int a,b;
        cin >> a >> b;
        AB[i].first=a-1;
        AB[i].second=b-1;
    }
    vector<long long> ans(M);
    UnionFind uf(N);
    ans[M-1]=N*(N-1)/2;
    for(int i=M-1;i>0;i--)
    {
        if(uf.same(AB[i].first,AB[i].second))
        {
            ans[i-1]=ans[i];
        }
        else
        {
            long long asize =(long long)uf.size(AB[i].first);
            long long bsize =(long long)uf.size(AB[i].second);
            uf.unite(AB[i].first,AB[i].second);
            ans[i-1]=ans[i]-asize*bsize;
        }
    }

    for(int i=0;i<M;i++)
    {
        cout << ans[i] << endl;
    }
}


Compiler output:
a.cc:2:15: error: expected ',' or ')', found "<<"
    2 | #define lson(o<<1)
      |               ^~
a.cc:3:15: error: expected ',' or ')', found "<<"
    3 | #define rson(o<<1|1)
      |               ^~
Language: C++

#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
const ll MAX=100001;

ll par[MAX]={};
ll ran[MAX]={};
ll si[MAX]={};
ll n,m;
ll fuben;

ll find(ll x)
{
	if(par[x]==0)
	{
		return x;
	}
	return par[x]find(par[x]);
}
void unite(ll x,ll y)
{
	x=find(x);
	y=find(y);
	if(x==y)
	{
		return;
	}
	if(ran[x]<ran[y])
	{
		par[x]=y;
		ll tmp=si[x]*(si[x]-1)/2+si[y]*(si[y]-1)/2;
		si[y]+=si[x];
		fuben-=si[y]*(si[y]-1)/2-tmp;
	}
	else
	{
		par[y]=x;
		ll tmp=si[x]*(si[x]-1)/2+si[y]*(si[y]-1)/2;
		si[x]+=si[y];
		fuben-=si[x]*(si[x]-1)/2-tmp;
		if(ran[x]==ran[y])
		{
			ran[x]++;
		}
	}
}
ll a[MAX]={};
ll b[MAX]={};
int main()
{    
	cin >> n >> m;
	fuben=n*(n-1)/2;
	for (ll i=1;i<=n;i++)
	{
	si[i]=1;
	}
	for (ll i=0;i<m;i++)
	{
	cin >> a[i] >> b[i];
		}
	stack <ll> v;
	for (ll i=m-1;i>=0;i--)
	{
	v.push(fuben);
	unite(a[i], b[i]);
	}
	while(!v.empty())
	{
	cout << v.top() << endl;
	v.pop();
	}
}



Compiler output:
a.cc: In function 'll find(ll)':
a.cc:68:22: error: expected ';' before 'find'
   68 |         return par[x]find(par[x]);
      |                      ^~~~
      |                      ;
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
const int MAX_N=10^5;
vector<pair<int, int> > edge;
int N, M;
int par[MAX_N];  //親
ll sizes[MAX_N]; //木の深さ
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        sizes[i] = 1;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
//併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x==y) return;
    if (par[x] > par[y]) swap(x, y); // merge technique
    par[y] =x;
    sizes[x] += sizes[y];
    }

bool same(int x,int y){
    return find(x)==find(y);
}

void solve(){
    init(N);
    ll ans[MAX_N];
    ans[M-1]=(ll)N*(N-1)/2;
    for(int i=M-1;i>=0;i--){
        int a=edge[i].first;
        int b=edge[i].second;
        if(same(a,b)=false){
        ans[i-1]=ans[i]-(ll)sizes[find(a)]*sizes[find(b)];
        unite(a,b);
        }
        else ans[i-1]=ans[i];
    }
    for(int i=0;i<M;i++)cout<<ans[i]<<'\n';
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N>>M;
    for(int i=0;i<M;i++) {
        int a, b;
        cin>>a>>b;
        a=a-1;
        b=b-1;
        edge.push_back(make_pair(a,b));
    }
    solve();
    return 0;
}

Compiler output:
a.cc:21:19: warning: result of '10^5' is 15; did you mean '1e5'? [-Wxor-used-as-pow]
   21 | const int MAX_N=10^5;
      |                   ^
      |                 ---
      |                 1e
a.cc:21:17: note: you can silence this warning by using a hexadecimal constant (0xa rather than 10)
   21 | const int MAX_N=10^5;
      |                 ^~
      |                 0xa
a.cc: In function 'void solve()':
a.cc:68:16: error: lvalue required as left operand of assignment
   68 |         if(same(a,b)=false){
      |            ~~~~^~~~~
Language: C++

#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
int root(vel &pa, int ser) {
	if (pa[ser] < 0) { return ser; }
	return root(pa, ser);
}
void marge(vel &pa, int a, int b) {
	a = root(pa, a);
	b = root(pa, b);
	int sia = -pa[a];
	int sib = -pa[b];
	if (a != b) {
		if (sia > sib) { pa[b] = a; pa[a] += pa[b]; }
		else { pa[a] = b; pa[b] = a; }
	}
}
bool issame(vel &pa, int a, int b) {
	return root(pa, a) == root(pa, b);
}
signed main() {
	int n; cin >> n;
	vel pa(n, -1);
	int m; cin >> m;
	vel a(m); vel b(m);
	for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	vel hube(m, (n*(n - 1)) / 2);
	for (int i = 0; i < m-1; i++) {
		hube[i + 1] = hube[i];
		if (!issame(pa,a[m - 1 - i], b[m - 1 - i])) {
			hube[i + 1] -= pa[root(pa,a[m - 1 - i])] * pa[root(pa,b[m - 1 - i])];
		}
		uni(pa,a[m - 1 - i], b[m - 1 - i]);
	}
	for (int i = 0; i < m; i++) { cout << hube[m-1-i] << endl; }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:17: error: 'uni' was not declared in this scope; did you mean 'unix'?
   41 |                 uni(pa,a[m - 1 - i], b[m - 1 - i]);
      |                 ^~~
      |                 unix
Language: C++

#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
int root(vel &pa, int ser) {
	if (pa[ser] < 0) { return ser; }
	return root(pa, ser);
}
void marge(vel &pa, int a, int b) {
	a = root(pa, a);
	b = root(pa, b);
	int sia = -pa[a];
	int sib = -pa[b];
	if (a != b) {
		if (sia > sib) { pa[b] = a; pa[a] += pa[b]; }
		else { pa[a] = b; pa[b] = a; }
	}
}
bool issame(vel &pa, int a, int b) {
	return root(pa, a) == root(pa, b);
}
signed main() {
	int n; cin >> n;
	vel pa(n, -1);
	int m; cin >> m;
	vel a(m); vel b(m);
	for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	vel hube(m, (n*(n - 1)) / 2);
	for (int i = 0; i < m-1; i++) {
		hube[i + 1] = hube[i];
		if (!issame(a[m - 1 - i], b[m - 1 - i], pa)) {
			hube[i + 1] -= pa[root(pa,a[m - 1 - i])] * pa[root(pa,b[m - 1 - i])];
		}
		uni(a[m - 1 - i], b[m - 1 - i], pa);
	}
	for (int i = 0; i < m; i++) { cout << hube[m-1-i] << endl; }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:28: error: invalid initialization of reference of type 'std::vector<long long int>&' from expression of type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}
   38 |                 if (!issame(a[m - 1 - i], b[m - 1 - i], pa)) {
      |                      ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:26:18: note: in passing argument 1 of 'bool issame(std::vector<long long int>&, long long int, long long int)'
   26 | bool issame(vel &pa, int a, int b) {
      |                  ^
a.cc:41:17: error: 'uni' was not declared in this scope; did you mean 'unix'?
   41 |                 uni(a[m - 1 - i], b[m - 1 - i], pa);
      |                 ^~~
      |                 unix
Language: Java

static class pair{
        int a,b;
        public pair(int o, int s){
            a = o;
            b = s;
        }
    }
    static int[] parent;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int totalpairs = n*(n-1)/2;
        parent = new int[n+1];
        Arrays.fill(parent,-1);
        pair[] bridges = new pair[m];
        for (int i = 0; i < m; i++){
            int k = sc.nextInt();
            int l = sc.nextInt();
            bridges[i] = new pair(k,l);
        }
        HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
        for (int i = 1; i <= n; i++){
            hm.put(i,1);
        }
        int[] print = new int[m];
        print[print.length-1] = totalpairs;
        for (int i = bridges.length-1; i >= 1; i--) {
            int num = 0;
            int paro = find(bridges[i].a);
            int pars = find(bridges[i].b);
            if (paro != pars) {
                parent[paro] = pars;
                hm.put(pars, hm.get(pars) + hm.get(paro));
                hm.remove(paro);
            }
            Iterator it =  hm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pair = (Map.Entry)it.next();
                num += (int)pair.getValue()*((int)pair.getValue()-1)/2;
            }
            print[i-1] = totalpairs-num;
        }
        for (int p : print) {
            System.out.println(p);
        }
    }

    static int find(int find){
        if (parent[find] == -1){
            return find;
        }else{
            return find(parent[find]);
        }
    }

Compiler output:
Main.java:8: error: unnamed classes are a preview feature and are disabled by default.
    static int[] parent;
           ^
  (use --enable-preview to enable unnamed classes)
1 error
Language: Java

import java.util.*;

public class DecayedBridges {
    static class pair{
        int a,b;
        public pair(int o, int s){
            a = o;
            b = s;
        }
    }
    static int[] parent;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int totalpairs = n*(n-1)/2;
        parent = new int[n+1];
        Arrays.fill(parent,-1);
        pair[] bridges = new pair[m];
        for (int i = 0; i < m; i++){
            int k = sc.nextInt();
            int l = sc.nextInt();
            bridges[i] = new pair(k,l);
        }
        HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
        for (int i = 1; i <= n; i++){
            hm.put(i,1);
        }
        int[] print = new int[m];
        print[print.length-1] = totalpairs;
        for (int i = bridges.length-1; i >= 1; i--) {
            int num = 0;
            int paro = find(bridges[i].a);
            int pars = find(bridges[i].b);
            if (paro != pars) {
                parent[paro] = pars;
                hm.put(pars, hm.get(pars) + hm.get(paro));
                hm.remove(paro);
            }
            Iterator it =  hm.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pair = (Map.Entry)it.next();
                num += (int)pair.getValue()*((int)pair.getValue()-1)/2;
            }
            print[i-1] = totalpairs-num;
        }
        for (int p : print) {
            System.out.println(p);
        }
    }

    static int find(int find){
        if (parent[find] == -1){
            return find;
        }else{
            return find(parent[find]);
        }
    }
}


Compiler output:
Main.java:3: error: class DecayedBridges is public, should be declared in a file named DecayedBridges.java
public class DecayedBridges {
       ^
1 error
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <time.h>

using namespace std;
typedef long long ll;

int N = 0;
int M = 0;
int x = 0;
int y = 0;

//?????????????????

struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }

    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;

        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }

        return r;

    }

    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }

};

int main(){

    cin >> N >> M;

    UnionFind test(N);

    vector<ll > ans;
    ll t_ans = 0;
    //初期状態：どの組み合わせも橋がないのでとても不便
    //ans.push_back((N * (N - 1)) / 2);
    t_ans = (N * (N - 1)) / 2;

    vector<ll> X;
    vector<ll> Y;
    for(int i = 0; i < M; i++){
        cin >> x >> y;
        X.push_back(x - 1);
        Y.push_back(y - 1);
    }

    //入力
    for(int i = M - 1; i >= 0; i--){
        ans.push_back(t_ans);
        if(test.same(X[i], Y[i]) == 1){
            continue;
        }
        
        //cout << test.FindSize(X[i]) * test.FindSize(Y[i]) << endl;
        //t_ans -= test.FindSize(X[i]) * test.FindSize(Y[i]);
        ll r = test.unite(X[i], Y[i]);
        t_ans -= r;

    }

    for(int i = ans.size() - 1 ; i >= 0 ; i--){
        cout << ans[i] << endl;
    }

}

Compiler output:
a.cc: In member function 'll UnionFind::unite(int, int)':
a.cc:51:13: error: return-statement with no value, in function returning 'll' {aka 'long long int'} [-fpermissive]
   51 |             return;
      |             ^~~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;
class UnionFind{

public:

    vector<int> Parent;


    //コンストラクタ
    UnionFind(int N){
        Parent = vector<int>(N,-1);

    }
    
    //aの根を返す
    int root(int a){
        if(Parent[a] < 0) return a;
        return root(Parent[a]);
    }

    //自分のいる木の頂点の数を返す関数
    int size(int a){
        return Parent(a) = Parent[root(a)];
    }

    //二つの木が同じ場合はtrueを返す
    bool sameTree(int a,int b){
        int ra = root(a);
        int rb = root(b);
        return ra == rb;

    }

    //異なる二つの木を結合する
    void unite(int a, int b){
        if(sameTree(a,b)) return;

        if(size(a) < size(b))swap(a,b);

        Parent[a] += Parent[b];
        Parent[b] = a;
    }

};

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N,M;
    cin >> N >> M;
    vector<int> A(M),B(M);

    for(int i = 0; i < M;i++){
        cin >> A[i] >> B[i];
        //配列を用意しているのは0-Nまでだからそこの位置に合わせている
        A[i]--;
        B[i]--;
    }

    vector<long long> ans(M);
    //引き始めの初期値はNC2を採用(Nこの中から2個を選択する繋げからからそのパターン通り存在)
	ans[M - 1] = (ll)N * (N - 1) / 2;

    UnionFind Uni(N);
    for(int i = M-1; i > 0;--i){
        ans[i-1] = ans[i];
        if(!Uni.sameTree(A[i],B[i])){
            ans[i-1] -= (ll)Uni.size(A[i])*Uni.size(B[i]);
            Uni.unite(A[i],B[i]);
        }
    }
    for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
    
    return 0;
}



Compiler output:
a.cc: In member function 'int UnionFind::size(int)':
a.cc:48:22: error: no match for call to '(std::vector<int>) (int&)'
   48 |         return Parent(a) = Parent[root(a)];
      |                ~~~~~~^~~
Language: C++

#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return Parent(a) = Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}



Compiler output:
a.cc: In member function 'int UnionFind::size(int)':
a.cc:27:31: error: 'a' was not declared in this scope
   27 |                 return Parent(a) = Parent[root(A)];//親をとってきたい]
      |                               ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
using int = long long;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

ll N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc:8:7: error: expected nested-name-specifier before 'int'
    8 | using int = long long;
      |       ^~~
Language: C++

#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
using int = long long;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

int N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc:8:7: error: expected nested-name-specifier before 'int'
    8 | using int = long long;
      |       ^~~
Language: C++

#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
typedef long long int;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

int N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc:8:19: error: declaration does not declare anything [-fpermissive]
    8 | typedef long long int;
      |                   ^~~
Language: C++

#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
typedef ll int;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

int N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc:8:9: error: multiple types in one declaration
    8 | typedef ll int;
      |         ^~
a.cc:8:12: error: declaration does not declare anything [-fpermissive]
    8 | typedef ll int;
      |            ^~~
Language: C++

#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
typedef int ll;

class UnionFind {
  std::vector<ll> p;  // parent??

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    // if (p[x] == p[y]) --p[x];
    // p[y] = x;
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  ll size(int x) { return -p[root(x)]; }
};

int N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc:8:13: error: conflicting declaration 'typedef int ll'
    8 | typedef int ll;
      |             ^~
a.cc:7:19: note: previous declaration as 'typedef long long int ll'
    7 | typedef long long ll;
      |                   ^~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

class UnionFind {
    private:
        ll node_num;
        vector<ll> parent;
        vector<ll> node_rank;
        vector<ll> sizes;
    public:
        UnionFind(ll n) {
            node_num = n;
            parent.resize(node_num);
            node_rank.resize(node_num);
            sizes.resize(node_num);
        }
        void init() {
            for (ll i = 0; i < node_num; i++) {
                parent[i] = i;
                node_rank[i] = 0;
                sizes[i] = 1;
            }
        }
        ll root(ll u) {
            return parent[u] == u ? u : parent[u] = root(parent[u]);
        }
        bool same(ll u, ll v) {
            return root(u) == root(v);
        }
        void unite(ll u, ll v) {
            u = root(u);
            v = root(v);
            if (u == v) return;
            if (node_rank[u] < node_rank[v]) {
                parent[u] = v;
                sizes[v] += sizes[u];
            }
            else {
                parent[v] = u;
                sizes[u] += sizes[v];
                if (node_rank[u] == node_rank[v]) {
                    node_rank[u]++;
                }
            }
        }
        ll get_size(ll u) {
            return sizes[root(u)];
        }
};

int main() {
    // This sample usage is Atcoder Beginners Contest 120 D
    ll N, M;
    cin >> N >> M;
    UnionFind UF(N);
    UF.init();
    vector<ll> A(M), B(M);
    for (ll i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    ll now_sizes = N * (N - 1) / 2;
    vector<ll> ans;
    for (ll i = M - 1; i >= 0; i--) {
        ans.push_back(now_sizes);
        if (UF.same(A[i], B[i])) {
            continue;
        }
        else {
            now_sizes -= UF.get_size(A[i]) * UF.get_size(B[i]);
            UF.unite(A[i], B[i]);
        }
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:76:5: error: 'reverse' was not declared in this scope
   76 |     reverse(ans.begin(), ans.end());
      |     ^~~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <unordered_set>

typedef long long ll;

using namespace std;

const ll N = 100001;
bool g[N][N];

ll CalConvience(ll n) {
    ll result = 0;
    vector<bool> visited(n, false);
    for(int i = 1; i <= n; ++i) {
        if(visited[i]) {
            continue;
        }
        
        // bfs from node i
        unordered_set<int> travelled;
        travelled.insert(i);
        
        queue<int> ique;
        ique.push(i);
        
        visited[i] = true;
        
        while(!ique.empty()) {
            int front = ique.front();
            ique.pop();
            
            for(int j = 1; j <= n; ++j) {
                if(visited[j]) {
                    continue;
                }
                
                if(g[front][j]) {
                    visited[j] = true;
                    ique.push(j);
                    travelled.insert(j);
                }
            }
        }
        if(travelled.size() == 1) {
            continue;
        }
        
        ll cur = (travelled.size()) * (travelled.size() - 1) / 2;
        result += cur;
    }
    return result;
}

int main() {
    memset(g, 0, sizeof(g));
    ll n = 0, m = 0;
    cin >> n >> m;

    vector<int> vs;
    vector<int> ve;
    for(int i = 0; i < m; ++i) {
        int s = 0, e = 0;
        cin >> s >> e;
        vs.push_back(s);
        ve.push_back(e);

        g[s][e] = true;
        g[e][s] = true;
    }
    
    ll total = CalConvience(n);
    for(int i = 0; i < m; ++i) {
        g[vs[i]][ve[i]] = false;
        g[ve[i]][vs[i]] = false;
        
        ll current = CalConvience(n);
        cout << "current is " << current << endl;
        ll inconvience = total - current;
        cout << inconvience << endl;
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:5: error: 'memset' was not declared in this scope
   58 |     memset(g, 0, sizeof(g));
      |     ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <unordered_set>
  +++ |+#include <cstring>
    6 |
Language: C++

#include <bits/stdc++.h>
using namespace std;

int find(int x, int par[]){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x], par);
    }
}

void unite(int x, int y, int par[], int size[]){
    x = find(x, par);
    y = find(y, par);
    if(x==y){
        return;
    }
    size[x] += size[y];
    par[y] = x;
    return;
}
 
int main(){
    int n, m, i;
    cin >> n >> m;
    int a[m], b[m], par[n], size[n];
    long int ans[m];
    for(i=0; i<n; i++){
        par[i] = i;
        size[i] = 1;
    }
    for(i=0; i<m; i++){
        cin >> a[i] >> b[m];
    }
    for(i=m-1; i>=0; i--){
        if(i == m-1){
            ans[i] = n*(n-1)/2;
        }else if(find(a[i], par) != find(b[i], par){
            int x = find(a[i], par), y = find(b[i], par);
            ans[i] = ans[i+1] - size[x]*size[y];
            unite(x, y, par, size);
        }
    }
    for(i=0; i<m; i++){
        cout << ans[i];
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:52: error: expected ')' before '{' token
   38 |         }else if(find(a[i], par) != find(b[i], par){
      |                 ~                                  ^
      |                                                    )
a.cc:43:5: error: expected primary-expression before '}' token
   43 |     }
      |     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
long long int a[100010],b[100010];
long long int ans[100010];
long long int f[100010];
long long findd(long long x) { return f[x] == x ? x : f[x] = findd(f[x]); }
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
        s[i]=1;
    }
    for(int i=0;i<m;i++)
    {
        scanf("%lld%lld",&a[i],&b[i]);
    }
    long long int sum=(n-1)*n/2;
    for(int i=m-1;i>=0;i--)
    {
        ans[i]=sum;
        int aa=findd(a[i]);
        int bb=findd(b[i]);
        if(aa!=bb)
        {
            f[bb]=aa;
            sum-=s[aa]*s[bb];
            s[aa]+=s[bb];
        }
    }
    for(int i=0;i<m;i++)
        printf("%lld\n",ans[i]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 's' was not declared in this scope
   14 |         s[i]=1;
      |         ^
a.cc:29:18: error: 's' was not declared in this scope
   29 |             sum-=s[aa]*s[bb];
      |                  ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct UnionFind {
  vector<long long> islandLinks;
  
  UnionFind(int n) : islandLinks(n, -1) {}
  
  int root(int x) {
    if(islandLinks[x] < 0) return x;
    return islandLinks[x] = root(islandLinks[x]);
  }
  
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  
  bool merage(int x, int y) {
    long long rootX = root(x), rootY = root(Y);
    if(rootX == rootY) return false;
    
    if(rootX > rootY) swap(rootX, rootY);
    islandLinks[rootX] += islandLinks[rootY];
    islandLinks[rootY] = rootX;
    return true;
  }
  
  long long size(int x) {
    return -islandLinks[root(x)];
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  
  for(int i = 0; i < M; i++){
    cin >> A[i] >> B[i];
  }
  
  long count = N*(N-1) * 0.5; 
  vector<long long> weights;
  
  UnionFind uf(N);
  for(int i = 0; i < M; i++) {
    weights.push_back(count);
    
    if(uf.isSame(A[N-1-i], B[N-1-i])) continue;
    
    long long sa = uf.size(A[N-1-i]), sb = uf.size(B[N-1-i]);
    count -= sa*sb;
    
    uf.merage(A[N-1-i],B[N-1-i]);
  }
  
  vector<long long>::reverse_iterator iter = weights.rbegin();
  while(iter != weights.rend()) {
    cout << *iter << endl;
    iter++;
  }
}

Compiler output:
a.cc: In member function 'bool UnionFind::merage(int, int)':
a.cc:22:45: error: 'Y' was not declared in this scope
   22 |     long long rootX = root(x), rootY = root(Y);
      |                                             ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m);
    vector<long long>ans(m);
    UnionFind tree(n);
    for(int i=0;i<m;i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    ans[m-1] = (long long)n*(n-1)/2;
    for(int i=m-1;i>=1;i--){
      ans[i-1] = ans[i];
      if(tree.root(x[i]) != tree.root(y[i])){
        ans[i-1] -= (long long)tree.size(x[i])*tree.size(y[i]);
        tree.unionSet(x[i], y[i])
      }
    }
    for(int i=0;i<m;i++){
      cout << ans[i];
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:34: error: expected ';' before '}' token
   43 |         tree.unionSet(x[i], y[i])
      |                                  ^
      |                                  ;
   44 |       }
      |       ~
Language: C++

#include<iostream>
#include<vector>
using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m);
    vector<long long>ans(m);
    UnionFind tree(n);
    for(int i=0;i<m;i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    ans[m-1] = (long long)n*(n-1)/2;
    for(int i=m-1;i>=1;i--){
      ans[i-1] = ans[i];
      if(tree.root(x[i]) != tree.root(y[i])){
        ans[i-1] -= (long long)tree.size(x[i])*tree.size(y[i]);
        tree.connect(x[i], y[i])
      }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:14: error: 'struct UnionFind' has no member named 'connect'
   43 |         tree.connect(x[i], y[i])
      |              ^~~~~~~
Language: C++

#include<iostream>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  int leader[100001];
  int size[100001];
  int A[100001];
  int B[100001];
  for (int i = 0; i < N; i ++) {
    leader[i] = i;
    size[i] = 1;
  }
  for (int i = 0; i < M; i ++) {
    cin >> A[i] >> B[i];
    A[i] --;
    B[i] --;
  }
  long long ans[100001];
  ans[M - 1] = (long long) N * (N - 1) / 2;
  for (int i = M - 1; i > 0; i ++) {
    int k = leader[A[i]];
    int j = leader[B[i]];
    while(leader[k] != k) k = leader[k];
    while(leader[j] != j) j = leader[j];
    ans[i - 1] = a[i];
    if (k != j) {
      ans[i - 1] -= size[k] * size[j];
      if (size[k] > size[j]) swap(k, j);
      leader[k] = leader[j];
    }
  }
  for (int i = 0; i < M; i ++) cout << ans[i] << endl;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:26:18: error: 'a' was not declared in this scope
   26 |     ans[i - 1] = a[i];
      |                  ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

struct UnionFind{
    vector<int> par;
    vector<int> sizes;
    UnionFind(int n):par(n),sizes(n,1){ rep(i,n)par[i]=i; }
    //find root of x
    int find(int x){
        if(x!=par[x]) par[x] = find(par[x]);
        return par[x];
    }
    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return find(x) == find(y); }
    int size(int x){ return sizes[find(x)]; }
};

int main() {
	ll N,M;
	cin>>N>>M;
	vector<ll> A(M),B(M);
	rep(i,N){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
	}
	vector<ll> ans(M);
	ans[M-1] = N*(N-1)/2;
	UnionFind uni(N);
	for (int i = M-1; i => 1; --i){
		if(uni.same(A[i],B[i])){
			ans[i-1] = ans[i]; 
		}
		else{
			ans[i-1] = ans[i]-uni.size(A[i])*uni.size(B[i]);
		}
	}
	rep(i,M){
		cout<<ans[i]<<endl;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:30: error: expected primary-expression before '>' token
   47 |         for (int i = M-1; i => 1; --i){
      |                              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

struct UnionFind{
    vector<int> par;
    vector<int> sizes;
    UnionFind(int n):par(n),sizes(n,1){ rep(i,n)par[i]=i; }
    //find root of x
    int find(int x){
        if(x!=par[x]) par[x] = find(par[x]);
        return par[x];
    }
    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return find(x) == find(y); }
    int size(int x){ return sizes[find(x)]; }
};

int main() {
	ll N,M;
	cin>>N>>M;
	vector<ll> A(M),B(M);
	rep(i,N){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
	}
	vector<ll> ans(M);
	ans[M-1] = N*(N-1)/2;
	UnionFind uni(N);
	for (int i = M-1; i => 1; --i){
		if(uni.same(A[i],B[i])){
			ans[i-1] = ans[i]; 
		}
		else{
			ans[i-1] = ans[i]-uf.size(A[i])*uf.size(B[i]);
		}
	}
	rep(i,M){
		cout<<ans[i]<<endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:30: error: expected primary-expression before '>' token
   47 |         for (int i = M-1; i => 1; --i){
      |                              ^
a.cc:52:43: error: 'uf' was not declared in this scope
   52 |                         ans[i-1] = ans[i]-uf.size(A[i])*uf.size(B[i]);
      |                                           ^~
Language: C++

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;

int N,M;
int fa[200005];
ll size[200005];
ll ans[200005];
int l[200005];
int r[200005];

int find(int x){
	return fa[x]==x? x: fa[x]=find(fa[x]);
}

int main(){
	while(cin>>N>>M;){
	ll tot =(N*(N-1))/2;
	ll cnt = 0;
	for(int i=1;i<=N;i++)
		fa[i] = i,size[i]=1;
		
	for(int i=1;i<=M;i++)
		cin>>l[i]>>r[i];
	ans[M+1] = tot;
	for(int i = M;i>=2;i--){
		//ans[i] = tot-cnt;
		int x = find(l[i]);
		int y = find(r[i]);
		if(x!=y){
			//cnt+=size[x]*size[y];
			ans[i] = ans[i+1]-size[x]*size[y];
			size[x]+=size[y];
			fa[y]=x;
		}
	}
	
	for(int i=2;i<=M+1;i++)
		cout<<ans[i]<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:24: error: expected ')' before ';' token
   24 |         while(cin>>N>>M;){
      |              ~         ^
      |                        )
a.cc:24:25: error: expected primary-expression before ')' token
   24 |         while(cin>>N>>M;){
      |                         ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
#define lli long long
#define rep0(i,j) for(lli i = 0; i<j; i++)
#define all(x) (x).begin(),(x).end()

lli edge[1000000][2];

struct UnionFind {
	UnionFind() {};
	vector<lli> data;
	UnionFind(lli size) : data(size, -1) { }
	//UnionFindのコンストラクタdataをsizeだけ確保してすべて-1で初期化する.

	bool unionSet(lli x, lli y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}

		return x != y;
	}//xとyが入ってる集合を併合する

	bool findSet(lli x, lli y) {
		return root(x) == root(y);
	}//xとyが同じ集合に入っているかを判定する

	lli root(lli x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}//親の番号を返す(自分自身が親の場合は自分の番号)

	lli size(lli x) {
		return -data[root(x)];
	}//木のサイズ？
};
/*親が-1, 子は親の子もしくは親の番号を持つ*/


int main() {
	lli N, M;
	cin >> N >> M;
	
	vector<lli> ans(M,0);

	UnionFind tree;
	tree./*UnionFind::*/UnionFind(N);

	rep0(i, M) {
		cin >> edge[i][0] >> edge[i][1];
		edge[i][0]--; edge[i][1]--;
	}

	tree.unionSet(edge[M - 1][0], edge[M - 1][1]);
	ans[0] = N * (N - 1) / 2;
	if(M!=1)ans[1] = ans[0] - 1;

	for (lli i = 1; i < M-1; i++) {
		if (tree.findSet(edge[M-i-1][0], edge[M-i-1][1])) {
			ans[i+1] = ans[i];
		}else{
			ans[i+1] = ans[i] - tree.size(edge[M - i - 1][0])*tree.size(edge[M - i - 1][1]);
		}
		tree.unionSet(edge[M - i - 1][0], edge[M - i - 1][1]);
	}	
	
	sort(all(ans));
	rep0(i, M) cout << ans[i] << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:29: error: invalid use of 'UnionFind::UnionFind'
   50 |         tree./*UnionFind::*/UnionFind(N);
      |                             ^~~~~~~~~