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

#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;
typedef int ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

struct UnionFind{
    vector<int> parent;
    vector<int> sizes;
    int N;
    UnionFind(int n){
        parent.resize(n);
        sizes.resize(n);
        N =  n;
        for(int i = 0; i < n; i++){
            parent[i] = i;
            sizes[i] = 1;
        }
    }

    int root(int s){
        if(parent[s] == s) return s;
        return root(parent[s]);
    }

    bool same(int s,int t){
        int rs = root(s);
        int rt = root(t);
        if(rs == rt) return true;
        else return false; 
    }

    void integrate(int s,int t){
        int rs = root(s);
        int rt = root(t);
        if(rs == rt) return;
        if(sizes[rs] >= sizes[rt]){
            parent[rt] = rs;
            sizes[rs] += sizes[rt];
        }
        else{
            parent[rs] = rt;
            sizes[rt] += sizes[rs];
        }
    }

    int renketu(int s){
        int rs = root(s);
        return sizes[rs];
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<pair<int,int>> road(m);
    for(int i = 0; i < m;i++){
        int a,b;
        cin >> a >> b;
        --a;--b;
        road[i] = make_pair(a,b);
    }
    int a = (n * n - n) / 2;
    int pre = 0;
    int ans[m+1];
    ans[m] = a;
    for(int i = m-1; i >= 0; --i){
        int x = road[i].first;
        int y = road[i].second;
        if(uf.same(x,y)){
            ans[i] = a - pre;
            continue;
        }
        pre += uf.renketu(x) * uf.renketu(y);
        ans[i] = a - pre;
        uf.integrate(x,y);
    }
    for(int i = 1; i <= m; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;
typedef int long long;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

struct UnionFind{
    vector<int> parent;
    vector<int> sizes;
    int N;
    UnionFind(int n){
        parent.resize(n);
        sizes.resize(n);
        N =  n;
        for(int i = 0; i < n; i++){
            parent[i] = i;
            sizes[i] = 1;
        }
    }

    int root(int s){
        if(parent[s] == s) return s;
        return root(parent[s]);
    }

    bool same(int s,int t){
        int rs = root(s);
        int rt = root(t);
        if(rs == rt) return true;
        else return false; 
    }

    void integrate(int s,int t){
        int rs = root(s);
        int rt = root(t);
        if(rs == rt) return;
        if(sizes[rs] >= sizes[rt]){
            parent[rt] = rs;
            sizes[rs] += sizes[rt];
        }
        else{
            parent[rs] = rt;
            sizes[rt] += sizes[rs];
        }
    }

    int renketu(int s){
        int rs = root(s);
        return sizes[rs];
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<pair<int,int>> road(m);
    for(int i = 0; i < m;i++){
        int a,b;
        cin >> a >> b;
        --a;--b;
        road[i] = make_pair(a,b);
    }
    int a = (n * n - n) / 2;
    int pre = 0;
    int ans[m+1];
    ans[m] = a;
    for(int i = m-1; i >= 0; --i){
        int x = road[i].first;
        int y = road[i].second;
        if(uf.same(x,y)){
            ans[i] = a - pre;
            continue;
        }
        pre += uf.renketu(x) * uf.renketu(y);
        ans[i] = a - pre;
        uf.integrate(x,y);
    }
    for(int i = 1; i <= m; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

struct unionfind
{
    vector<ll> d;

    unionfind(ll n) : d(n, -1) {}

    ll root(ll x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        else
        {
            return d[x] = root(d[x]);
        }
    }

    bool unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);

        if (x == y)
        {
            return false;
        }

        if (d[x] > d[y])
        {
            swap(x, y);
        }

        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

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

ll main(void)
{
    ll n, m;

    cin >> n >> m;

    unionfind u(n + 1);
    stack<P> s;
    set<ll> t;
    vector<ll> ans(m, 0);

    for (ll i = 0; i < m; i++)
    {
        ll a, b;

        cin >> a >> b;

        a--;
        b--;

        s.push(P(a, b));
    }

    ll res = 0;

    ans[m - 1] = (n * n - n) / 2;

    for (ll i = 1; i < m; i++)
    {
        P p = s.top();
        s.pop();

        if (u.same(p.first, p.second))
        {
            ans[m - i - 1] = ans[m - i];
        }
        else
        {
            ans[m - i - 1] = ans[m - i] - u.size(p.first) * u.size(p.second);
        }

        u.unite(p.first, p.second);
    }

    for (auto a : ans)
    {
        cout << a << endl;
    }
}


Compiler output:
a.cc:74:1: error: '::main' must return 'int'
   74 | ll main(void)
      | ^~
Language: C++

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

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];
    //1-indexからだから
    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--){
    //繋がってなかったのが繋がったとき
    if (Uni.root(A[i])!=Uni.root(B[i])){
      ans[i-1]=ans[i]-(long long)Uni.size(A[i])*Uni.size(B[i]);
      Uni.connect(A[i],B[i]);
    }
    else ans[i-1]=ans[i];
  }
  for (int i=0;i<M;++i){
    cout << ans[i] << endl;
  }
}

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;//自分がリーダーなのでAを返す
    return Parent[A] = root(Parent[A]);//親を繋ぎ変えてる
  }
  
  //自分のいるグループの頂点数を調べる
  int size(int A) {
     return -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);
    
    //2つをくっつける処理
    //Aのサイズを更新する
    Parent[A]+=Parent[B];
    //Bの親をAに変更する
    Parent[B]=A;
    
    return true;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:3: error: 'UnionFind' was not declared in this scope
   18 |   UnionFind Uni(N);
      |   ^~~~~~~~~
a.cc:22:9: error: 'Uni' was not declared in this scope
   22 |     if (Uni.root(A[i])!=Uni.root(B[i])){
      |         ^~~
a.cc: At global scope:
a.cc:76:2: error: expected '}' at end of input
   76 | }
      |  ^
a.cc:33:17: note: to match this '{'
   33 | class UnionFind {
      |                 ^
a.cc: In member function 'int UnionFind::size(int)':
a.cc:55:29: error: a function-definition is not allowed here before '{' token
   55 |   bool connect(int A,int B) {
      |                             ^
a.cc: At global scope:
a.cc:76:2: error: expected unqualified-id at end of input
   76 | }
      |  ^
Language: C++

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

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];
  
  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--){
    //繋がってなかったのが繋がったとき
    if (Uni.root(A[i])!=Uni.root(B[i])){
      ans[i-1]=ans[i]-(long long)Uni.size(A[i])*Uni.size(B[i]);
      Uni.connect(A[i],B[i]);
    }
    else ans[i-1]=ans[i];
  }
  for (int i=0;i<M;++i){
    cout << ans[i] << endl;
  }
}

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;//自分がリーダーなのでAを返す
    return Parent[A] = root(Parent[A]);//親を繋ぎ変えてる
  }
  
  //自分のいるグループの頂点数を調べる
  int size(int A) {
     return -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);
    
    //2つをくっつける処理
    //Aのサイズを更新する
    Parent[A]+=Parent[B];
    //Bの親をAに変更する
    Parent[B]=A;
    
    return true;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: 'UnionFind' was not declared in this scope
   13 |   UnionFind Uni(N);
      |   ^~~~~~~~~
a.cc:17:9: error: 'Uni' was not declared in this scope
   17 |     if (Uni.root(A[i])!=Uni.root(B[i])){
      |         ^~~
a.cc: At global scope:
a.cc:71:2: error: expected '}' at end of input
   71 | }
      |  ^
a.cc:28:17: note: to match this '{'
   28 | class UnionFind {
      |                 ^
a.cc: In member function 'int UnionFind::size(int)':
a.cc:50:29: error: a function-definition is not allowed here before '{' token
   50 |   bool connect(int A,int B) {
      |                             ^
a.cc: At global scope:
a.cc:71:2: error: expected unqualified-id at end of input
   71 | }
      |  ^
Language: Java

import java.util.Scanner;

public class Main 
{
	static int n,m;
	static int[] a, b;
	static int[] par; //parent of an element
	static int[] rank; //rank of an element
	static long[] size;
	static long score = 0;
	
	static void union(int a, int b)
	{
		//when union-ing 2 different elements, the root of one of the two elements
		//becomes the parent of the other element's root.
		int ra = root(a);
		int rb = root(b);
		if(ra == rb)return;
		
		int sa = size[ra];
//		System.out.println("size was " + size[ra] + " " + size[rb]);
		long lost1 = ((size[ra]*size[ra])-(size[ra]))/2;
		long lost2 = ((size[rb]*size[rb])-(size[rb]))/2;
//		System.out.println("lost " + lost1 + " " + lost2);
		score += -lost1 -lost2;
		size[ra] = size[ra]+size[rb];
		size[rb] = size[ra];
		score += (((size[ra]*size[ra])-(size[ra]))/2);
//		System.out.println("size now " + size[ra]);
		
		if(rank[ra] >= rank[rb])
		{ //a's root is higher ranked means it should be the parent
			par[rb] = ra;
			if(rank[ra] == rank[rb])rank[rb]++; //if they're same rank,
			//ra's height is now increased due to having rb as a child, so ra's rank is increased
		}
		else par[ra] = rb;
	}
	
	static int root(int i) //alternate name: root()
	{ 
		//unless this is the root (parent == self), walk up the parents and find the root
		//then set that root as the direct parent of this node (path compression)
		if(par[i] != i)
			par[i] = root(par[i]); //path compression
		return par[i];
	}
	
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		par = new int[n];
		rank = new int[n];
		size = new long[n];
		
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			size[i]=1;
		}
		
		for(int i = m-1; i >= 0; i--)
		{
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
//			union(a[i],b[i]);
//			System.out.println("pairs now: " + score);
		}
		
//		if(true)
		long init = (n*(n-1))/2;
		long[] note = new long[m];
		for(int i = 0; i < m; i++)
		{
//			System.out.println("Consider " + i + ": " + a[i] + " " + b[i]);
//			System.out.println("debug " + (init-score));
			note[i] = init-score;
			union(a[i],b[i]);
		}
//		System.out.println("debug " + (init-score));
		
		for(int i = m-1; i >= 0; i--)
		{
			System.out.println(note[i]);
		}
	}

}


Compiler output:
Main.java:20: error: incompatible types: possible lossy conversion from long to int
		int sa = size[ra];
		             ^
1 error
Language: Java

import java.util.Scanner;

public class Main 
{
	static int n,m;
	static int[] a, b;
	static int[] par; //parent of an element
	static int[] rank; //rank of an element
	static long[] size;
	static long score = 0;
	
	static void union(int a, int b)
	{
		//when union-ing 2 different elements, the root of one of the two elements
		//becomes the parent of the other element's root.
		int ra = root(a);
		int rb = root(b);
		if(ra == rb)return;
		
		int sa = size[ra];
//		System.out.println("size was " + size[ra] + " " + size[rb]);
		long lost1 = ((size[ra]*size[ra])-(size[ra]))/2;
		long lost2 = ((size[rb]*size[rb])-(size[rb]))/2;
//		System.out.println("lost " + lost1 + " " + lost2);
		score += -lost1 -lost2;
		size[ra] = size[ra]+size[rb];
		size[rb] = size[ra];
		score += (((size[ra]*size[ra])-(size[ra]))/2);
//		System.out.println("size now " + size[ra]);
		
		if(rank[ra] >= rank[rb])
		{ //a's root is higher ranked means it should be the parent
			par[rb] = ra;
			if(rank[ra] == rank[rb])rank[rb]++; //if they're same rank,
			//ra's height is now increased due to having rb as a child, so ra's rank is increased
		}
		else par[ra] = rb;
	}
	
	static int root(int i) //alternate name: root()
	{ 
		//unless this is the root (parent == self), walk up the parents and find the root
		//then set that root as the direct parent of this node (path compression)
		if(par[i] != i)
			par[i] = root(par[i]); //path compression
		return par[i];
	}
	
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		par = new int[n];
		rank = new int[n];
		size = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			size[i]=1;
		}
		
		for(int i = m-1; i >= 0; i--)
		{
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
//			union(a[i],b[i]);
//			System.out.println("pairs now: " + score);
		}
		
//		if(true)
		long init = (n*(n-1))/2;
		long[] note = new long[m];
		for(int i = 0; i < m; i++)
		{
//			System.out.println("Consider " + i + ": " + a[i] + " " + b[i]);
//			System.out.println("debug " + (init-score));
			note[i] = init-score;
			union(a[i],b[i]);
		}
//		System.out.println("debug " + (init-score));
		
		for(int i = m-1; i >= 0; i--)
		{
			System.out.println(note[i]);
		}
	}

}


Compiler output:
Main.java:20: error: incompatible types: possible lossy conversion from long to int
		int sa = size[ra];
		             ^
Main.java:58: error: incompatible types: int[] cannot be converted to long[]
		size = new int[n];
		       ^
2 errors
Language: C++

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
uf = UnionFind(n)
bridges = []
for i in range(m):
    ai,bi = map(int,input().split())
    bridges.append((ai,bi))
bridges = bridges[::-1]
answers = []
for i in range(m):
    ans = 1
    for j in uf.roots():
        x = uf.size(j)
        ans += x*(n-x)
    ans //= 2
    answers.append(ans)
    uf.union(bridges[i][0]-1,bridges[i][1]-1)
answers = answers[::-1]
for i in range(m):
    print(answers[i])

Compiler output:
a.cc:46:26: warning: multi-character literal with 6 characters exceeds 'int' size of 4 bytes
   46 |         return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      |                          ^~~~~~~~
a.cc:1:17: error: expected unqualified-id before ')' token
    1 | class UnionFind():
      |                 ^
a.cc:45:5: error: 'def' does not name a type
   45 |     def __str__(self):
      |     ^~~
Language: C++

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

class UnionFind {
public:
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);
    for(int im=0;im<m;im++) {
        cin >> a.at(im) >> b.at(im); a.at(im)--; b.at(im)--;
    }

    UnionFind uf = UnionFind(n);

    vector<ll> ans(m);
    ll n1, n2, tmp;
    tmp = n*(n-1)/2;
    int atmp, btmp;
    for(int im=0;im<m;im++) {
        ans.at(m-1-im) = tmp;
        atmp = a.at(m-1-im);
        btmp = b.at(m-1-im);
        if(uf.issame(atmp, btmp)) continue;
        n1 = uf.size(atmp);
        n2 = uf.size(btmp);
        tmp -= n1 * n2;
        uf.unite(atmp, btmp);
    }

    for(int im=0;im<m;im++) {
        cout << ans.at(im) << endl;
    }

    return 0;
}


Compiler output:
a.cc: In member function 'int UnionFind::find(int)':
a.cc:24:30: error: 'root' was not declared in this scope
   24 |         else return par[x] = root(par[x]);
      |                              ^~~~
a.cc: In member function 'bool UnionFind::issame(int, int)':
a.cc:28:16: error: 'root' was not declared in this scope
   28 |         return root(x) == root(y);
      |                ^~~~
a.cc: In member function 'bool UnionFind::unite(int, int)':
a.cc:32:13: error: 'root' was not declared in this scope
   32 |         x = root(x); y = root(y);
      |             ^~~~
a.cc: In member function 'int UnionFind::size(int)':
a.cc:41:21: error: 'root' was not declared in this scope
   41 |         return -par[root(x)];
      |                     ^~~~
Language: C++

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

class UnionFind {
public:
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);
    for(int im=0;im<m;im++) {
        cin >> a.at(im) >> b.at(im); a.at(im)--; b.at(im)--;
    }

    UnionFind uf = UnionFind(n);

    vector<ll> ans(m);
    ll n1, n2, tmp;
    tmp = n*(n-1)/2;
    int atmp, btmp;
    for(int im=0;im<m;im++) {
        ans.at(m-1-im) = tmp;
        atmp = a.at(m-1-im);
        btmp = b.at(m-1-im);
        if(uf.same(atmp, btmp)) continue;
        n1 = uf.size(atmp);
        n2 = uf.size(btmp);
        tmp -= n1 * n2;
        uf.unite(atmp, btmp);
    }

    for(int im=0;im<m;im++) {
        cout << ans.at(im) << endl;
    }

    return 0;
}


Compiler output:
a.cc: In member function 'int UnionFind::find(int)':
a.cc:24:30: error: 'root' was not declared in this scope
   24 |         else return par[x] = root(par[x]);
      |                              ^~~~
a.cc: In member function 'bool UnionFind::issame(int, int)':
a.cc:28:16: error: 'root' was not declared in this scope
   28 |         return root(x) == root(y);
      |                ^~~~
a.cc: In member function 'bool UnionFind::unite(int, int)':
a.cc:32:13: error: 'root' was not declared in this scope
   32 |         x = root(x); y = root(y);
      |             ^~~~
a.cc: In member function 'int UnionFind::size(int)':
a.cc:41:21: error: 'root' was not declared in this scope
   41 |         return -par[root(x)];
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:65:15: error: 'class UnionFind' has no member named 'same'; did you mean 'issame'?
   65 |         if(uf.same(atmp, btmp)) continue;
      |               ^~~~
      |               issame
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
struct Union_Find{
  vi par,size;
  Union_Find(int N):par(N),size(N){
    rep(i,0,N) par[i]=i;
  }
  int root(int X){
    if(par[X]==X) return X;
    return root(par[X]);
  }
  int unite(int X,int Y){
    int RX=root(X),RY=root(Y);
    if(RX==RY) return 0;
    par[RY]=RX;
    int ret=(size[RX]+size[RY])*(size[RX]+size[RY]-1)/2-size[RX]*(size[RX]-1)/2-size[RY]*(size[RY]-1)/2;
    size[RX]+=size[RY];
    size[RY]=0;
    return ret;
  }
};
signed main(){
  int N,M; cin>>N>>M;
  vi A(M),B(M);
  rep(i,0,M) cin>>A[i];
  rep(i,0,M) cin>>B[i];
  vi ans(M);
  reverse(ALL(A));
  reverse(ALL(B));
  Union-Find tree(N);
  int sum=0;
  rep(i,0,M){
    sum+=tree.unite(A[i]-1,B[i]-1);
    ans[i]=sum;
  }
  rep(i,0,M) cout<<N*(N-1)/2-ans[i]<<endl;
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:46:3: error: 'Union' was not declared in this scope; did you mean 'union'?
   46 |   Union-Find tree(N);
      |   ^~~~~
      |   union
a.cc:46:9: error: 'Find' was not declared in this scope
   46 |   Union-Find tree(N);
      |         ^~~~
a.cc:49:10: error: 'tree' was not declared in this scope; did you mean 'free'?
   49 |     sum+=tree.unite(A[i]-1,B[i]-1);
      |          ^~~~
      |          free
Language: C++

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

struct UnionFind {
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N) {
        for (int i = 0; i < N; ++i) {
            par[i] = i;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        siz[ry] = siz[ry] + siz[rx];
    }

    int size(int x) {
        return siz[root(x)];
    }

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

ll cmb(ll n) {
    return n * (n - 1) / 2;
}

int main() {
    int N, M;
    cin >> N >> M;

    int A[M], B[M];
    for (int i = 0; i < M; ++i) cin >> A[i] >> B[i];

    // 逆からデータ構造を構築する方が効率的
    reverse(A, A + M);
    reverse(B, B + M);

    int t = 0;
    ll ans[M];
    UnionFind uf(N);
    map<int, int> mp;
    for (int i = 0; i < M ; ++i) {

        int aa = A[i] - 1;
        int bb = B[i] - 1;

        if (i == 0) {
            ans[i] = cmb(N);
        }
        else {
            ans[i] = cmb(N);
            for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
                ans[i] -= cmb(itr->first) * itr->second;
            }
        }

        int siza = uf.size(aa);
        int sizb = uf.size(bb);
        int flg = uf.same(aa, bb);

        uf.unite(aa, bb);
        int sizab = uf.size(aa);

        if (!flg) {
            if (mp.count(siza) != 0) mp[siza] -= 1;
            if (mp.count(sizb) != 0) mp[sizb] -= 1;
            if (mp.count(sizab) != 0) {
                mp[sizab] += 1;
            }
            else {
                mp[sizab] = 1;
            }
        }
    }

    reverse(ans, ans + M);

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

    return 0;
}

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

#include<bits/stdc++.h>
#define MAXN 100005
using namespace std;
long long fa[MAXN],a[MAXN],b[MAXN],cnt[MAXN],ans[MAXN];
long long find1(long long v)
{
    return fa[v]=fa[v]==v?v:find1(fa[v]);
}
void merge1(long long x,long long y)
{
    fa[a1]=b1;
    cnt[b1]+=cnt[a1];
}
int main()
{

    long long n,m;
    cin>>n>>m;
    for(long long i=0;i<n;i++)
    {
        fa[i]=i;
        cnt[i]=1;
    }
    for(long long i=0;i<m;i++)
        cin>>a[i]>>b[i];
    ans[m-1]=n*(n-1)/2;
    for(long long i=m-1;i>0;i--)
    {
        long long x=find1(a[i]);
        long long y=find1(b[i]);
        if(x!=y)
        {
            ans[i-1]=ans[i]-cnt[x]*cnt[y];
            merge1(x,y);
        }
        else
            ans[i-1]=ans[i];
    }
    for(long long i=0;i<m;i++)
        cout<<ans[i]<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'void merge1(long long int, long long int)':
a.cc:11:8: error: 'a1' was not declared in this scope; did you mean 'y1'?
   11 |     fa[a1]=b1;
      |        ^~
      |        y1
a.cc:11:12: error: 'b1' was not declared in this scope; did you mean 'y1'?
   11 |     fa[a1]=b1;
      |            ^~
      |            y1
Language: C++

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

struct UnionFind{
	vector<long> par;

	UnionFind(long N) : par(N) {
		for(long i=0;i<N;++i) par[i] = i;
	}

	long root(long x){
		if(par[x] == x) return x;
		else root(par[x]);
	}

	void unite(long x, long y){
		long rx = root(x);
		long ry = root(y);
		if(rx == ry) return;
		else par[rx] = ry;
	}

	bool same(long x, long y){
		long rx = root(x);
		long ry = root(y);
		return rx == ry;
	}
};

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

	UnionFind tree(N);

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

	for(long i=0;i<N;++i){
		size[i] = 1;
	}

	for(long i=M-1;i>=0;--i){
		if(!tree.same(A[i], B[i]) & i>0){
			ans[i-1] = ans[i] - size[tree.root(A[i])]*size[tree.root(B[i])];
			long a = size[tree.root(A[i])];
			long b = size[tree.root(B[i])];
			size[tree.root(A[i])] += b;
			size[tree.root(B[i])] += a;
			tree.unite(A[i], B[i]);
		}
		else if(i>0){
			ans[i-1] = ans[i];
		}
	}
	for(long i=0;i<M;++i){
		cout<<ans[i]<<endl;
	}
}


Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In member function 'long int UnionFind::root(long int)':
a.cc:16:26: warning: control reaches end of non-void function [-Wreturn-type]
   16 |                 else root(par[x]);
      |                      ~~~~^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int fa[maxn];
int T;
struct Node
{
    int x,y;
}e[maxn];
int Find(int x)
{
    if(fa[x]==x)
        return x;
    else
        return fa[x]=Find(fa[x]);
}
int x,y,n,m;
ll sum;
ll ans[maxn],f[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i,f[i]=1;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&e[i].x,&e[i].y);
    }
    sum=n*(n-1)/2;
    for(int i=m;i>=1;i--)
    {

        ans[i]=sum;
        x=e[i].x,y=e[i].y;
        x=Find(x);

        y=Find(y);
        if(x==y)
            continue;

        fa[y]=x;
        sum-=f[x]*f[y];
        f[x]+=f[y];
        //ans[i]=sum;
        //cout<<"====="<<endl;
    }
    for(int i=1;i<=m;i++)
       printf("%lld\n",ans[i]);
}


Compiler output:
a.cc:18:1: error: 'll' does not name a type
   18 | ll sum;
      | ^~
a.cc:19:1: error: 'll' does not name a type
   19 | ll ans[maxn],f[maxn];
      | ^~
a.cc: In function 'int main()':
a.cc:24:17: error: 'f' was not declared in this scope
   24 |         fa[i]=i,f[i]=1;
      |                 ^
a.cc:29:5: error: 'sum' was not declared in this scope
   29 |     sum=n*(n-1)/2;
      |     ^~~
a.cc:33:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   33 |         ans[i]=sum;
      |         ^~~
      |         abs
a.cc:42:14: error: 'f' was not declared in this scope
   42 |         sum-=f[x]*f[y];
      |              ^
a.cc:48:24: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |        printf("%lld\n",ans[i]);
      |                        ^~~
      |                        abs
Language: C++

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}
	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return size[root(x)];
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(m),b(m);
  rep(i,m) cin>>a[i]>>b[i];
  vll ans(m);
  UnionFind<ll> uf(n+1);
  ans[m-1]=(n*(n-1)/2);
  for(int i=m-1;i>0;i++){
    if(uf.same(a[i],b[i])){
      ans[i-1]=ans[i];
    }
    else{
      ans[i-1]=ans[i]-uf.size(a[i])*uf.size(b[i]);
      uf.unite(a[i],b[i]);
    }
  }
  rep(i,m){
    COUT(ans[i]);
  }
}

Compiler output:
a.cc: In instantiation of 'T UnionFind<T>::size(T) [with T = long long int]':
a.cc:86:30:   required from here
   86 |       ans[i-1]=ans[i]-uf.size(a[i])*uf.size(b[i]);
      |                       ~~~~~~~^~~~~~
a.cc:70:18: error: invalid use of member function 'T UnionFind<T>::size(T) [with T = long long int]' (did you forget the '()' ?)
   70 |           return size[root(x)];
      |                  ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) sizes.push_back(1);
    return;
  }

  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  ll size(ll n) {
    return sizes[root(a)];
  }

  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    sizes[root(a)] += sizes[root(b)];
    parent[root(b)] = root(a);
    return;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  vll a(m), b(m);
  for (ll i = 0; i < m; i++) cin >> a[i] >> b[i];

  struct union_find uf;
  uf.init(n);

  ll unconv = n * (n - 1) / 2;
  vll ans(1, unconv);

  for (ll i = m - 1; i > 0; i--) {
    if (!uf.is_united(a[i] - 1, b[i] - 1)) {
      unconv -= uf.size(a[i] - 1) * uf.size(b[i] - 1);
    }
    uf.unite(a[i] - 1, b[i] - 1);
    ans.push_back(unconv);
  }

  for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl;
}

Compiler output:
a.cc: In member function 'll union_find::size(ll)':
a.cc:31:23: error: 'a' was not declared in this scope
   31 |     return sizes[root(a)];
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll size;

  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) size.push_back(1);
    return;
  }

  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  void unite(ll a, ll b) {
    ll ra = root(a), rb = root(b);
    parent[rb] = ra;
    size[ra] += size[rb];
    return;
  }

  void is_united(ll a, ll b) {
    return (root(a) == root(b));
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  vll a(m), b(m);
  for (ll i = 0; i < m; i++) cin >> a[i] >> b[i];

  struct union_find uf;
  uf.init(n);

  ll unconv = n * (n - 1) / 2;
  vll ans(1, unconv);

  for (ll i = m - 1; i > 0; i--) {
    ll x = uf.root(a[i] - 1), y = uf.root(b[i] - 1);
    if (!uf.is_united(x, y)) {
      unconv -= uf.size[x] * uf.size[y];
      uf.unite(x, y);
    }
    ans.push_back(unconv);
  }

  for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl;
}

Compiler output:
a.cc: In member function 'void union_find::is_united(ll, ll)':
a.cc:38:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
   38 |     return (root(a) == root(b));
      |            ~~~~~~~~~^~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:57:22: error: could not convert 'uf.union_find::is_united(x, y)' from 'void' to 'bool'
   57 |     if (!uf.is_united(x, y)) {
      |          ~~~~~~~~~~~~^~~~~~
      |                      |
      |                      void
a.cc:57:22: error: in argument to unary !
Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
  int N, M;
  cin >> N >> M;
  int A[M], B[M];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    A[i] = a-1;
    B[i] = b-1;
  }

  /* Uion-find というデータ構造を使えば処理時間を短縮できるらしい */
  // cf. https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396
  // cf. https://atc001.contest.atcoder.jp/tasks/unionfind_a

  int par[N]; // par[i]... iの親
  int mem[N]; // iの(自分も含めた) 子の構成島数
  rep(i, N) par[i] = i; // 最初は全て自分が親
  rep(i, N) mem[i] = 1;

  auto root = [&](int x) { // x の根を返す
    // 自身が親と同一の時まで再帰的にrootをたどる
    if(par[x]==x) return x;
    else {
      return root(par[x]);
    }
  };

  auto unite = [&](int x, int y) {
    if(root(x)==root(y)) return;
    else {
      par[root(x)] = root(y); // xのunionのrootの親をyの根にする。
      mem[root(y)] += mem[root(x)]; // yの根の構成員に xの根の構成員を加える
      return;
    }
  };

  ////////////////////

  int ans[M]; // ans
  ans[M-1] = N*(N-1)/2; // 全ての橋が崩壊した時の不便さ
  for(int i=M-1; i>0; i--) {
    if(root(A[i])==root(B[i])) ans[i-1] = ans[i];
    else {
      ans[i-1] = ans[i] - mem[root(A[i])]*mem[root(B[i])];
      unite(A[i], B[i]);
    }    
  }

  rep(i, M) {
    cout << ans[i] << endl;
  }

  return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:46:14: error: use of 'root' before deduction of 'auto'
   46 |       return root(par[x]);
      |              ^~~~
Language: C++

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

struct UnionFind {
    vector<ll> par;  // 親
    vector<ll> siz;  // 親

    UnionFind(ll N) : par(N), siz(N, 1){ //最初は全てが根であるとして初期化
        for(ll i=0; i < N; i++) par[i] = i;
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);  // 小を大にくっつける
        par[ry] = rx;
        siz[rx] += siz[ry];
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x) {
        return siz[root(x)];
    }

};


int main() {
    ll N, M;
    cin >> N >> M;

    vector<pair<ll, ll>> Bridges(M-1);
    for (ll i=0; i<M; i++) {
        ll a, b; 
        cin >> a >> b; 
        --a;
        --b;
        if (i==0) continue;
        pair<ll, ll> p = {a, b};
        Bridges[M-1-i] = p;
    }

    UnionFind tree(N);
    vector<ll> res(M);
    res[0] = N*(N-1)/2;
    ll i = 1;
    for (pair<ll, ll>& bridge: Bridges) {
        if (tree.same(bridge.first, bridge.second)) {
            res[i] = res[i-1];
        } else {
            ll sizx = tree.size(bridge.first);
            ll sizy = tree.size(bridge.second);
            tree.unite(bridge.first, bridge.second);
            res[i] = res[i-1] - (sizx * sizy);
        }
        ++i;
    }

    reverse(res.begin(), res.end());  

    for (ll r: res) {
        cout << r << endl;
    }

    return 0;
}

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

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

inlinen long long read()
{
	long long f=1, x=0;
	char ch=getchar;
	
	while(!isdigit(ch))
	{
		if(ch=='-')
		{
			f=-1;
		}
		
		ch=getchar();
	}
	
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		
		ch=getchar();
	}
}

const int maxn=1e5+5;
int n, m, fa[maxn];

struct Edge
{
	int u, v;
}edge[maxn];

long long ans[maxn], sz[maxn];

int get_fa(int x)
{
	if(x==fa[x])
	{
		return x;
	}
	
	return fa[x]=get_fa(fa[x]);
}

int main()
{
	ios::sync_with_stfio(0);
	
	cin.tie(0);
	
	n=read();
	m=read();
	
	for(int i=1; i<=m; i++)
	{
		e[i].u=read();
		e[i].v=read();
	}
	
	for(int i=1; i<=n; i++)
	{
		fa[i]=i;
		sz[i]=1;
	}
	
	ans[m]=(long long)n*(n-1)/2;
	
	for(int i=m; i>=1; i--)
	{
		int u=get_fa(e[i].u);
		v=get_fa(e[i].v);
		
		if(u==v)
		{
			ans[i-1]=ans[i];
		}
		else
		{
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u];
			fa[u]=v;
		}
	}
	
	for(int i=1; i<=n; i++)
	{
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Compiler output:
a.cc:4:1: error: 'inlinen' does not name a type; did you mean 'inline'?
    4 | inlinen long long read()
      | ^~~~~~~
      | inline
a.cc: In function 'int main()':
a.cc:49:14: error: 'sync_with_stfio' is not a member of 'std::ios' {aka 'std::basic_ios<char>'}
   49 |         ios::sync_with_stfio(0);
      |              ^~~~~~~~~~~~~~~
a.cc:53:15: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   53 |         n=read();
      |           ~~~~^~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:54:15: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   54 |         m=read();
      |           ~~~~^~
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:58:17: error: 'e' was not declared in this scope
   58 |                 e[i].u=read();
      |                 ^
a.cc:58:28: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   58 |                 e[i].u=read();
      |                        ~~~~^~
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:59:28: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   59 |                 e[i].v=read();
      |                        ~~~~^~
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:72:30: error: 'e' was not declared in this scope
   72 |                 int u=get_fa(e[i].u);
      |                              ^
a.cc:73:17: error: 'v' was not declared in this scope
   73 |                 v=get_fa(e[i].v);
      |                 ^
Language: C

/*
参考にしたもの
・蟻本
・drkenさんのライブラリ
https://github.com/drken1215/algorithm/blob/master/DataStructure/union_find_tree_size.cpp
辺のverifyはしていない（は？）
*/

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;


struct UnionFind{
    vector<int> par;
    vector<int> es;
    UnionFind(int N) : par(N,-1),es(N,0) {}
    
    //初期化
    void init(int N){
        par.assign(N,-1);
        es.assign(N,0);
    }

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

    int usize(int x) {return -par[find(x)];}

    int esize(int x) {return es[find(x)];}
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        es[x]++;
        if(x==y) return;

        if(usize(x)<usize(y)) swap(x,y);
        par[x]+=par[y];
        es[x]+=es[y];
        par[y]=x;
    }

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

};

signed main(void){
    int N,M;
    cin>>N>>M;
    int A[110000],B[110000];
    for(int i=1;i<=M;i++){
        cin>>A[i]>>B[i];
        A[i]--; B[i]--;
    } 

    ll now=(ll)N*(N-1)/2;
    vector<ll> ans;
    UnionFind uf(N);
    ans.push_back(now);
    for(int i=M;i>=2;i--){
        int a=A[i],b=B[i];
        if(uf.same(a,b)) ;
        else{
            now-=(ll)uf.usize(a)*uf.usize(b);
            uf.unite(a,b);
        }
        ans.push_back(now);
    }
    reverse(ans.begin(),ans.end());
    for(int i:ans){
        cout<<i<<endl;
    }
}

Compiler output:
main.c:9:9: fatal error: cstdio: No such file or directory
    9 | #include<cstdio>
      |         ^~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;

template <class T>
using lim = numeric_limits<T>;

int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	ll n, m;
	cin >> n >> m;
	int a[m], b[m];
	
	for (int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	
	// holds pointers to parents
	int arr[n];
	// holds how many nodes are in the set
	int counter[n];
	for (int i = 0; i < n; i++){
		counter[i] = 1;
		arr[i] = i;
	}
	
	ll ans[m];
	// all disjoint
	ans[m-1] = ((n-1)*n)/2;
	for (int i = m-1; i >= 1; i--){
		int u = a[i];
		int v = b[i];
		while(counter[u]==0){
			u = arr[u];
		} 
		while(counter[v]==0){
			v = arr[v];
		}
		
		int cu = counter[u];
		int cv = counter[v];
		if (u != v){
			// small-to-large trick
			if (cu >= cv){
				counter[u] += counter[v];
				counter[v] = 0;
				
				ans[i-1] -= cu*cv
				arr[v] = u;
			}
			else{
				counter[v] += counter[u];
				counter[u] = 0;
				
				ans[i-1] -= cu*cv
				arr[u] = v;
			}
		}else{
			ans[i-1] = ans[i];
		}
	}
	
	for (int i = 0; i < m; i++){
		cout << ans[i] << endl;
	}
} 


Compiler output:
a.cc: In function 'int main()':
a.cc:54:50: error: expected ';' before 'arr'
   54 |                                 ans[i-1] -= cu*cv
      |                                                  ^
      |                                                  ;
   55 |                                 arr[v] = u;
      |                                 ~~~               
a.cc:61:50: error: expected ';' before 'arr'
   61 |                                 ans[i-1] -= cu*cv
      |                                                  ^
      |                                                  ;
   62 |                                 arr[u] = v;
      |                                 ~~~