criyle/codenet-compile-errors huggingface dataset:
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:25: error: cannot call constructor 'UnionFind::UnionFind' directly
   50 |         tree.UnionFind::UnionFind(N);
      |                         ^~~~~~~~~
Language: C++


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

using ll = long long;
const int MAX_V = 100000;
// const int MAX_V = 6;


struct UnionFind {
    vector<int> par;

    explicit UnionFind(int n) : par(n, -1) { }
    // void init(int n) { par.assign(n, -1); }

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

    bool is_same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    bool unite(int x, int y) {
        int root_x = find_root(x);
        int root_y = find_root(y);
        if (root_x == root_y) return false;
        if (par[root_x] > par[root_y]) swap(root_x, root_y); // unite technique
        par[root_x] += par[root_y];
        par[root_y] = root_x;
        return true;
    }

    ll size(int x) {
        return -par[find_root(x)];
    }
};

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

    int n, m;
    cin >> n >> m;

    UnionFind uf(n + 1);
    int a[m], b[m];
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
    }

    ll res[m];
    memset(res, 0, sizeof(res));

    res[m - 1] = n * (n - 1) / 2;
    for (int i = m - 1; i > 0; --i) {
        if (uf.is_same(a[i], b[i])){
            res[i - 1] = res[i];
        } else {
            res[i - 1] = res[i] - 1LL * uf.size(a[i]) * uf.size(b[i]) ;
        }
        uf.unite(a[i], b[i]);
    }

    for (auto r: res) {
        cout << r << '\n';
    }

    return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++



int main(){
    int mod=1000000007;
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int> a(m), b(m);
    for (int i=0;i<m;i++) {
        scanf("%d %d",&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++) printf("%lld\n",ans[i]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'scanf' was not declared in this scope
    6 |     scanf("%d %d",&n,&m);
      |     ^~~~~
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<int> a(m), b(m);
      |     ^~~~~~
a.cc:7:12: error: expected primary-expression before 'int'
    7 |     vector<int> a(m), b(m);
      |            ^~~
a.cc:9:24: error: 'a' was not declared in this scope
    9 |         scanf("%d %d",&a[i],&b[i]);
      |                        ^
a.cc:9:30: error: 'b' was not declared in this scope
    9 |         scanf("%d %d",&a[i],&b[i]);
      |                              ^
a.cc:14:12: error: expected primary-expression before 'long'
   14 |     vector<long long> ans(m);
      |            ^~~~
a.cc:15:5: error: 'ans' was not declared in this scope
   15 |     ans[m-1] = (long long)n*(n-1)/2;
      |     ^~~
a.cc:16:5: error: 'UnionFind' was not declared in this scope
   16 |     UnionFind uni(n);
      |     ^~~~~~~~~
a.cc:19:13: error: 'uni' was not declared in this scope; did you mean 'unix'?
   19 |         if (uni.root(a[i]) != uni.root(b[i])) {
      |             ^~~
      |             unix
a.cc:19:22: error: 'a' was not declared in this scope
   19 |         if (uni.root(a[i]) != uni.root(b[i])) {
      |                      ^
a.cc:19:40: error: 'b' was not declared in this scope
   19 |         if (uni.root(a[i]) != uni.root(b[i])) {
      |                                        ^
a.cc:24:27: error: 'printf' was not declared in this scope
   24 |     for (int i=0;i<m;i++) printf("%lld\n",ans[i]);
      |                           ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 |
Language: C++

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

long long int ans[100001];
int color[100000];
int bridge[100000][2];
int island[100000];


int main(){
	int nowcolor=0;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<100000;i++){
		ans[i]=0;color[i]=0;bridge[i][0]=0;bridge[i][1]=0;island[i]=-1;
	}
	for(int i=0;i<m;i++){scanf("%d %d",&bridge[i][0],&bridge[i][1]);bridge[i][0]--;bridge[i][1]--;}
	
	for(int i=m-1;i>=0;i--){
		//cout<<"   ans["<<i+1<<"]="<<ans[i+1]<<"    ";
		if(island[bridge[i][0]]==-1 and island[bridge[i][1]]==-1){
			island[bridge[i][0]]=island[bridge[i][1]]=nowcolor;
			color[nowcolor]=2;
			nowcolor++;
			ans[i]=ans[i+1]+1;
			//cout<<"n";
		}
		else{
			if(island[bridge[i][0]]==-1 and island[bridge[i][1]]!=-1){swap(bridge[i][0],bridge[i][1]);}
			if(island[bridge[i][1]]==-1 and island[bridge[i][0]]!=-1){
				island[bridge[i][1]]=island[bridge[i][0]];
				color[island[bridge[i][0]]]++;
				int k=color[island[bridge[i][0]]];
				ans[i]=ans[i+1]+(k-1);
				//cout<<"N";
			}
			else if(island[bridge[i][1]]!=-1 and island[bridge[i][0]]!=-1){
				if(island[bridge[i][1]]==island[bridge[i][0]]){ans[i]=ans[i+1];}
				else{
					int ccolor=island[bridge[i][0]];
					int lcolor=island[bridge[i][1]];
					ans[i]=ans[i+1]-(color[ccolor]*(color[ccolor]-1)/2)-(color[lcolor]*(color[lcolor]-1)/2)+((color[ccolor]+color[lcolor])*((color[ccolor]+color[lcolor])-1)/2);
					color[ccolor]+=color[lcolor];
					color[lcolor]=0;
					for(int j=0;j<n;j++){
						if(island[j]==lcolor){island[j]=ccolor;}
					}
					//cout<<"c";
				}
			}
		}
		//for(int j=0;j<n;j++){cout<<island[j]<<" ";}
		//cout<<"   ans["<<i<<"]="<<ans[i];
		//cout<<endl;
	}
	
	
	long long int anss=n*(n-1)/2;
	for(int i=1;i<=m;i++){
		cout<<p=anss-ans[i]<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:23: error: 'p' was not declared in this scope
   61 |                 cout<<p=anss-ans[i]<<endl;
      |                       ^
a.cc:61:36: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator<<'
   61 |                 cout<<p=anss-ans[i]<<endl;
      |                         ~~~~~~~~~~~^~~~~~
Language: Java

import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int m = in.nextInt();
    int[] l = new int[m];
    int[] r = new int[m];
    for (int i = m-1; i >= 0; i--)
    {
      l[i] = in.nextInt()-1;
      r[i] = in.nextInt()-1;
    }
    
    int[] size = new int[n];
    Arrays.fill(size, 1);
    long[] ans = new long[m];
    DSU d = new DSU(n);
    for (int i = 0; i < m; i++)
    	if (d.find(l[i]) != d.find(r[i]))
        {
          int a = size[d.find(l[i])];
          int b = size[d.find(r[i])];
          ans[m-1-i] = a*b;
          d.union(l[i], r[i]);
          size[d.find(l[i])] = a+b;
        }
    for (int i = 1; i < m; i++)
    {
      ans[i] += ans[i-1];
      System.out.println(ans[i]);
    }
    
    in.close();
  }
  
  public static class DSU
    {
        int[] set;
        
        DSU(int n)
        {
            Arrays.fill(set = new int[n], -1);
        }
        
        int find(int i)
        {
            return set[i] < 0 ? i : (set[i] = find(set[i]));
        }
        
        boolean union(int a, int b)
        {
            if ((a = find(a)) == (b = find(b))) return false;
            if (set[a] == set[b]) set[a]--;
            if (set[a] <= set[b]) set[b] = a; else set[a] = b;
            s--;
            return true;
        }
    }
}

Compiler output:
Main.java:59: error: cannot find symbol
            s--;
            ^
  symbol:   variable s
  location: class DSU
1 error
Language: Java

import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int m = in.nextInt();
    int[] l = new int[m];
    int[] r = new int[m];
    for (int i = m-1; i >= 0; i--)
    {
      l[i] = in.nextInt();
      r[i] = in.nextInt();
    }
    
    int[] size = new int[n];
    Arrays.fill(size, 1);
    long[] ans = new long[m];
    DSU d = new DSU(n);
    for (int i = 0; i < m; i++)
    	if (d.find(l[i]) != d.find(r[i]))
        {
          int a = size[d.find(l[i])];
          int b = size[d.find(r[i])];
          ans[m-1-i] = a*b;
          d.union(l[i], r[i]);
          size[d.find(l[i])] = a+b;
        }
    for (int i = 1; i < m; i++)
    {
      ans[i] += ans[i-1];
      System.out.println(ans[i]);
    }
    
    in.close();
  }
  
  public static class DSU
    {
        int[] set;
        
        DSU(int n)
        {
            Arrays.fill(set = new int[n], -1);
        }
        
        int find(int i)
        {
            return set[i] < 0 ? i : (set[i] = find(set[i]));
        }
        
        boolean union(int a, int b)
        {
            if ((a = find(a)) == (b = find(b))) return false;
            if (set[a] == set[b]) set[a]--;
            if (set[a] <= set[b]) set[b] = a; else set[a] = b;
            s--;
            return true;
        }
    }
}

Compiler output:
Main.java:59: error: cannot find symbol
            s--;
            ^
  symbol:   variable s
  location: class DSU
1 error
Language: C++

#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;
 
public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    REP(i,m) cin >> a[i] >> b[i];
    vector<ll> ans(m);
    union_find uf(n+1);
    ll fai = (n*(n-1))/2;
    ans[m-1] = fai;
    for (int i = m-2; i >= 0; --i) {
        if(!uf.same(a[i], b[i])) {
            ans[i] = ans[i+1]-uf.show_size(a[i+1])*uf.show_size(b[i+1]);
            uf.unite(a[i+1], b[i+1]);
        }
        else ans[i] = ans[i+1];
    }
    REP(i,m) cout << ans[i] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:59:5: error: 'union_find' was not declared in this scope; did you mean 'UnionFind'?
   59 |     union_find uf(n+1);
      |     ^~~~~~~~~~
      |     UnionFind
a.cc:63:13: error: 'uf' was not declared in this scope
   63 |         if(!uf.same(a[i], b[i])) {
      |             ^~
Language: C++

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


Compiler output:
a.cc: In function 'int main()':
a.cc:33:7: error: 'children' was not declared in this scope; did you mean 'cildren'?
   33 |       children[b][size[b]] = a;
      |       ^~~~~~~~
      |       cildren
Language: C++

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




struct UnionFind {
	vector<int> data;
	UnionFind(int n) {
		data.assign(n, -1);
	}

	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (data[a] > data[b])swap(a, b);
		data[a] += data[b];
		data[b] = a;

	}

	int find(int k)
	{
		if (data[k] < 0)return k;
		return (data[k] = find(data[k]));
	}

	int size(int k)
	{
		return -data[find(k)];
	}
};


#define long long int
signed main()
{
	int N, M, A[100005], B[100005];
	cin >> N >> M;
	UnionFind UF(N);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}
	int ret = 0;
	vector<int>ans(M);
	vector< int > ans(M);
	for (int i = M - 1; i >= 0; i--) {
		ans[i] = 1LL * N * (N - 1) / 2 - ret;
		if (UF.find(A[i]) != UF.find(B[i])) {
			ret += 1LL * UF.size(A[i]) * UF.size(B[i]);
			UF.unite(A[i], B[i]);
		}
	}
	for (auto &p : ans) cout << p << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:23: error: redeclaration of 'std::vector<int> ans'
   54 |         vector< int > ans(M);
      |                       ^~~
a.cc:53:20: note: 'std::vector<int> ans' previously declared here
   53 |         vector<int>ans(M);
      |                    ^~~
Language: C++

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




struct UnionFind {
	vector<int> data;
	UnionFind(int n) {
		data.assign(n, -1);
	}

	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (data[a] > data[b])swap(a, b);
		data[a] += data[b];
		data[b] = a;

	}

	int find(int k)
	{
		if (data[k] < 0)return k;
		return (data[k] = find(data[k]));
	}

	int size(int k)
	{
		return -data[find(k)];
	}
};


#define long long int
signed main()
{
	int N, M, A[100005], B[100005];
	cin >> N >> M;
	UnionFind UF(N);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}
	int ret = 0;
	vector<int>ans(M);
	vector< int > ans(M);
	for (int i = M - 1; i >= 0; i--) {
		ans[i] = 1LL * N * (N - 1) / 2 - ret;
		if (UF.find(A[i]) != UF.find(B[i])) {
			ret += 1LL * UF.size(A[i]) * UF.size(B[i]);
			uf.unite(A[i], B[i]);
		}
	}
	for (auto &p : ans) cout << p << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:23: error: redeclaration of 'std::vector<int> ans'
   54 |         vector< int > ans(M);
      |                       ^~~
a.cc:53:20: note: 'std::vector<int> ans' previously declared here
   53 |         vector<int>ans(M);
      |                    ^~~
a.cc:59:25: error: 'uf' was not declared in this scope; did you mean 'UF'?
   59 |                         uf.unite(A[i], B[i]);
      |                         ^~
      |                         UF
Language: C++

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

Compiler output:
a.cc: In function 'int main()':
a.cc:30:24: error: no match for call to '(std::vector<int>) (int&)'
   30 |         cildren[b][size(b) + j] = cildren[a][j];
      |                    ~~~~^~~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
class UnionFind {
  //子供は親を、おやは-(グループのサイズ)
  vector<int> Parent;
public:
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
  }
  int get(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = get(Parent[A]);
  }
  int size(int A) {
    return -Parent[get(A)];
  }
  bool connect (int A, int B) {
    A = get(A);
    B = get(B);
    if (A == B) return false; // 親が一緒なら何もしない
    if (size(A) > size(B)) {
      Parent[A] = -(size(A) + size(B));
      Parent[B] = A;
      return true;
    }
    Parent[B] = -(size(A) + size(B));
    Parent[A] = B;
    return true;
  }
  
      
int main () {
  int N, M;
  cin >> N >> M;
  long long max = N * (N - 1) / 2;
  vector<int>A(M);
  vector<int>B(M);
  for (int i = 0; i < M; i ++) cin >> A[i] >> B[i];
  UnionFind jun(N);
  vector<long long>ans(M);
  ans [M - 1] = max;
  for (int i = M - 1; i > 0; i --) {
    ans[i - 1] = ans[i] - size(A[i]) * size(B[i]);
    if (!jun.connect(A[i], B[i])) {
      ans[i - 1] = ans[i];
    }
  }
  for (int i = 0; i < M; i ++) cout << ans[i] << endl;
}


Compiler output:
a.cc:50:2: error: expected '}' at end of input
   50 | }
      |  ^
a.cc:4:17: note: to match this '{'
    4 | class UnionFind {
      |                 ^
a.cc: In member function 'int UnionFind::main()':
a.cc:50:1: warning: no return statement in function returning non-void [-Wreturn-type]
   50 | }
      | ^
a.cc: At global scope:
a.cc:50:2: error: expected unqualified-id at end of input
   50 | }
      |  ^
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); // 要素数Nのベクトルの要素を全て-1で初期化
    }
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A)
    {
        return -Parent[0]; //親をとってきたい
    }

    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];
        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>= 0; i++)
    {
        ans[i - 1] = A[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]);
        }
    }
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
}


Compiler output:
a.cc:52:2: error: expected ';' after class definition
   52 | }
      |  ^
      |  ;
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); // 要素数Nのベクトルの要素を全て-1で初期化
    }
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A)
    {
        return -Parent[0]; //親をとってきたい
    }

    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];
        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>= 0; i++)
    {
        ans[i - 1] = A[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]);
        }
    }
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
}


Compiler output:
a.cc:52:2: error: expected ';' after class definition
   52 | } int main()
      |  ^
      |  ;
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); // 要素数Nのベクトルの要素を全て-1で初期化
    }
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A])
    }

    int size(int A)
    {
        return -Parent[0]; //親をとってきたい
    }

    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];
        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>= 0; i++)
    {
        ans[i - 1] = A[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]);
        }
    }
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
}


Compiler output:
a.cc:52:2: error: expected ';' after class definition
   52 | } int main()
      |  ^
      |  ;
a.cc: In member function 'int UnionFind::root(int)':
a.cc:24:5: error: expected ';' before '}' token
   24 |     }
      |     ^
Language: C++

#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
UnionFind;
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>= 0; i++)
    {
        ans[i - 1] = A[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]);
        }
    }
    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); // 要素数Nのベクトルの要素を全て-1で初期化
    }
    int root(int A){
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A])
    }

    int size(int A) {
        return -Parent[0]; //親をとってきたい
    }

    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];
        Parent[B] = A;

        return true;
    }
}

Compiler output:
a.cc:7:1: error: 'UnionFind' does not name a type
    7 | UnionFind;
      | ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:22:5: error: 'UnionFind' was not declared in this scope
   22 |     UnionFind Uni(N);
      |     ^~~~~~~~~
a.cc:28:13: error: 'Uni' was not declared in this scope
   28 |         if (Uni.root(A[i]) != Uni.root(B[i])) {
      |             ^~~
a.cc: At global scope:
a.cc:76:2: error: expected ';' after class definition
   76 | }
      |  ^
      |  ;
a.cc: In member function 'int UnionFind::root(int)':
a.cc:52:5: error: expected ';' before '}' token
   52 |     }
      |     ^
Language: C++

#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
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>= 0; i++)
    {
        ans[i - 1] = A[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]);
        }
    }
    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); // 要素数Nのベクトルの要素を全て-1で初期化
    }
    int root(int A){
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A])
    }

    int size(int A) {
        return -Parent[0]; //親をとってきたい
    }

    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];
        Parent[B] = A;

        return true;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:5: error: 'UnionFind' was not declared in this scope
   20 |     UnionFind Uni(N);
      |     ^~~~~~~~~
a.cc:26:13: error: 'Uni' was not declared in this scope
   26 |         if (Uni.root(A[i]) != Uni.root(B[i])) {
      |             ^~~
a.cc: At global scope:
a.cc:74:2: error: expected ';' after class definition
   74 | }
      |  ^
      |  ;
a.cc: In member function 'int UnionFind::root(int)':
a.cc:50:5: error: expected ';' before '}' token
   50 |     }
      |     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1<<29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


class UnionFind {
    public:
    vector<int> Parent;

    UnionFind(int N){
        Parent = vint(N, -1);
    }

    int root(int A){
        if(Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
        return -Parent[root(A)];
    }

    bool connect(int A, int B){
        A = root(A);
        B = root(B);
        if(A == B){
            return false;
        }

        if(size(A) < size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};


int main(){
    int N, M; cin >> N >> M;
    vint A(M), B(M);
    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<ll> ans(M);
    ans[M - 1] = (ll)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] = ans[i] - (ll) Uni.size(A[i]  * Uni.size(B[i]));
            Uni.connect(A[i], B[i]);
    }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:70:2: error: expected '}' at end of input
   70 | }
      |  ^
a.cc:46:11: note: to match this '{'
   46 | int main(){
      |           ^
Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// マラソン用時間計測
clock_t start_clock;
constexpr double time_limit = 1.919114514; // 実行時間[s]より0.1ms程度余裕をあける
constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
inline bool intime() { return nowtime() < time_limit; }

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (int i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (int i=(is), i##_end=(ie); i<=i##_end; i++)
#define FOREACH(i, arr) for (auto &i : arr)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using ll = long long;
using namespace std;

// 汎用クラス
struct union_find {
    vector<int> par;
    vector<int> num;
    union_find(int n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// main前実行のためのダミークラス
class preexec_dummy {
    preexec_dummy() {
        start_clock = clock();
    }
} preexec_dummy_instance;

// Let's comp(u|e)te!
int main() {
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m, 0), b(m, 0);
    union_find uf(n);
    REP(i, m) {
        cin >> a[i] >> b[i];
        // make them 0-indexed
        a[i]--;
        b[i]--;
    }

    vector<ll> ans(m, 0);
    ans[m-1] = (ll)n * ((ll)n - 1ll) / 2ll;
    for (int i = m-1; i--;) {

        if (!uf.same(a[i+1], b[i+1])) {
            int na = uf.num[uf.root(a[i+1])];
            int nb = uf.num[uf.root(b[i+1])];
            ans[i] = ans[i+1] - (ll)na * (ll)nb;
            uf.unite(a[i+1], b[i+1]);
        } else {
            ans[i] = ans[i+1];
        }

    }

    REP(i, m) cout << ans[i] << endl;
    
}


Compiler output:
a.cc:60:3: error: 'preexec_dummy::preexec_dummy()' is private within this context
   60 | } preexec_dummy_instance;
      |   ^~~~~~~~~~~~~~~~~~~~~~
a.cc:57:5: note: declared private here
   57 |     preexec_dummy() {
      |     ^~~~~~~~~~~~~
Language: Java

object Main{
	def main(A:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n,m=s.nextInt
		val u=new UF(n)
		val a=Seq.fill(m)((s.nextInt-1,s.nextInt-1)).reverse.map(o=>{
			if(u.isConnected(o _1,o _2))
				0
			else{
				val t=u.groupSize(o _1)*u.groupSize(o _2)
				u.connect(o _1,o _2)
				t
			}
		}).reverse.toArray
		(1 until m) foreach(i=>a(i)+=a(i-1))
		a foreach println
	}
}
class UF(n:Int){
	val a = Array.fill(n)(-1)
	def root(t:Int):Int =
		if(a(t) < 0) t
		else {
			val v = root(a(t))
			a(t) = v
			v
		}
	def connect(b:Int,c:Int) ={
		val d = root(b)
		val e = root(c)
		if(d == e)
			false
		else {
			def f(g:Int,h:Int) ={
				a(g) += a(h);
				a(h) = g;
			}
			if(a(d) > a(e)) f(e,d) else f(d,e)
			true
		}
	}
	def isConnected(a:Int,b:Int) = root(a) == root(b)
	def groupSize(t:Int) = -a(root(t))
}

Compiler output:
Main.java:1: error: class, interface, enum, or record expected
object Main{
^
Main.java:19: error: '{' expected
class UF(n:Int){
        ^
Main.java:20: error: ';' expected
	val a = Array.fill(n)(-1)
	                     ^
Main.java:21: error: <identifier> expected
	def root(t:Int):Int =
	          ^
Main.java:22: error: <identifier> expected
		if(a(t) < 0) t
		         ^
Main.java:22: error: illegal start of type
		if(a(t) < 0) t
		          ^
Main.java:22: error: <identifier> expected
		if(a(t) < 0) t
		              ^
Main.java:24: error: ';' expected
			val v = root(a(t))
			                  ^
Main.java:25: error: ';' expected
			a(t) = v
			        ^
Main.java:26: error: not a statement
			v
			^
Main.java:26: error: ';' expected
			v
			 ^
Main.java:28: error: <identifier> expected
	def connect(b:Int,c:Int) ={
	             ^
Main.java:29: error: ';' expected
		val d = root(b)
		               ^
Main.java:30: error: ';' expected
		val e = root(c)
		               ^
Main.java:32: error: not a statement
			false
			^
Main.java:32: error: ';' expected
			false
			     ^
Main.java:34: error: ';' expected
			def f(g:Int,h:Int) ={
			     ^
Main.java:34: error: not a statement
			def f(g:Int,h:Int) ={
			        ^
Main.java:34: error: ';' expected
			def f(g:Int,h:Int) ={
			           ^
Main.java:34: error: not a statement
			def f(g:Int,h:Int) ={
			              ^
Main.java:34: error: ';' expected
			def f(g:Int,h:Int) ={
			                 ^
Main.java:38: error: ';' expected
			if(a(d) > a(e)) f(e,d) else f(d,e)
			                      ^
Main.java:38: error: ';' expected
			if(a(d) > a(e)) f(e,d) else f(d,e)
			                                  ^
Main.java:42: error: <identifier> expected
	def isConnected(a:Int,b:Int) = root(a) == root(b)
	                 ^
24 errors
Language: Java

import java.util.*;

import com.sun.swing.internal.plaf.basic.resources.basic;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[m];
        int b[] = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        //答えがintに収まらないためlong型を使う
        long[] ans = new long[m];
        //最後は全ての橋が壊れているのでN個から2つを選ぶ分だけある（Combination）
        ans[m - 1] = (long) n * (n - 1) / 2;
        UnionFind uni = new UnionFind(n);
        for (int i = m - 1; i >= 1; i--) {
            //繋がってなかったのが繋がった時
            if (uni.root(a[i]) != uni.root(b[i])) {
                ans[i - 1] = (long) ans[i] - 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++){
            System.out.println(ans[i]);
        }
    }
    
    static class UnionFind{
        ArrayList<Integer> parent;

        UnionFind(int n) {
            parent = new ArrayList<Integer>();
            Integer[] values = new Integer[n];
            //初期値セット、作るときは全て-1にする。こうすることで全てバラバラになる
            Arrays.fill(values, -1);
            //初期値を配列に入れる
            parent.addAll(Arrays.asList(values));
        }
        //Aがどのグループに属しているか調べる
        int root(int a) {
            if (parent.get(a) < 0) {
                return a;
            } else {
                int root = root(parent.get(a));
                parent.set(a, root);
                return root;
            }
        }

        //自分のいるグループの頂点数を調べる
        int size(int a) {
            return -parent.get(root(A));
        }

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

            //大きい方に小さい方をくっつける
            //Bのほうが大きい場合はAとBを入れ替える
            if (size(a) < size(b)) {
                int tmp = a;
                a = b;
                b = tmp;

            }

            parent.set(a, parent.get(a) + parent.get(b));
            parent.set(b, a);

            return true;

        }



    }
}

Compiler output:
Main.java:3: error: package com.sun.swing.internal.plaf.basic.resources is not visible
import com.sun.swing.internal.plaf.basic.resources.basic;
                                        ^
  (package com.sun.swing.internal.plaf.basic.resources is declared in module java.desktop, which does not export it)
Main.java:60: error: cannot find symbol
            return -parent.get(root(A));
                                    ^
  symbol:   variable A
  location: class UnionFind
2 errors
Language: Java

import java.util.*;

import com.sun.swing.internal.plaf.basic.resources.basic;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[m];
        int b[] = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        //答えがintに収まらないためlong型を使う
        long[] ans = new long[m];
        //最後は全ての橋が壊れているのでN個から2つを選ぶ分だけある（Combination）
        ans[m - 1] = (long) n * (n - 1) / 2;
        UnionFind uni = new UnionFind(n);
        for (int i = m - 1; i >= 1; i--) {
            //繋がってなかったのが繋がった時
            if (uni.root(a[i]) != uni.root(b[i])) {
                ans[i - 1] = (long) ans[i] - 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++){
            System.out.println(ans[i]);
        }
    }
    
    static class UnionFind{
        ArrayList<Integer> parent;

        UnionFind(int n) {
            parent = new ArrayList<Integer>();
            Integer[] values = new Integer[N];
            //初期値セット、作るときは全て-1にする。こうすることで全てバラバラになる
            Arrays.fill(values, -1);
            //初期値を配列に入れる
            parent.addAll(Arrays.asList(values));
        }
        //Aがどのグループに属しているか調べる
        int root(int a) {
            if (parent.get(a) < 0) {
                return a;
            } else {
                int root = root(parent.get(a));
                parent.set(a, root);
                return root;
            }
        }

        //自分のいるグループの頂点数を調べる
        int size(int a) {
            return -parent.get(root(A));
        }

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

            //大きい方に小さい方をくっつける
            //Bのほうが大きい場合はAとBを入れ替える
            if (size(a) < size(b)) {
                int tmp = a;
                a = b;
                b = tmp;

            }

            parent.set(a, parent.get(a) + parent.get(b));
            parent.set(b, a);

            return true;

        }



    }
}

Compiler output:
Main.java:3: error: package com.sun.swing.internal.plaf.basic.resources is not visible
import com.sun.swing.internal.plaf.basic.resources.basic;
                                        ^
  (package com.sun.swing.internal.plaf.basic.resources is declared in module java.desktop, which does not export it)
Main.java:41: error: cannot find symbol
            Integer[] values = new Integer[N];
                                           ^
  symbol:   variable N
  location: class UnionFind
Main.java:60: error: cannot find symbol
            return -parent.get(root(A));
                                    ^
  symbol:   variable A
  location: class UnionFind
3 errors
Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int fa[maxn];
int n,m;
ll num[maxn];
void init()
{
	repd(i,0,n)
	{
		fa[i]=i;
		num[i]=1;
	}
}
struct node
{
	int f;
	int t;
}b[maxn];
ll cnt[maxn];
int findpar(int x)
{
	if(x==fa[x])
	{
		return x;
	}else
	{
		fa[x]=findpar(fa[x]);
	num[x]=max(num[x],num[faX[x]]);
//		num[fa[x]]=max(num[x],num[fa[x]]);
		return fa[x];
	}
	// return x==fa[x]?x:fa[x]=findpar(f[x]);
}
void Merg(int x,int y)
{
	x=findpar(x);
	y=findpar(y);
	if(x!=y)
	{
		fa[x]=y;
		num[y]+=num[x];
	}
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>m;
	init();
	repd(i,1,m)
	{
		cin>>b[i].f>>b[i].t;
	}
	ll v;
	for(int i=m;i>=1;i--)
	{

		if(findpar(b[i].t)!=findpar(b[i].f))
		{
		    v=num[b[i].t]*num[b[i].f];
		    Merg(b[i].t,b[i].f);
			cnt[i]=v;
		}
	}
	ll ans=0;
	repd(i,1,m)
	{
		ans+=cnt[i];
		cout<<ans<<endl;
	}


    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Compiler output:
a.cc: In function 'int findpar(int)':
a.cc:65:31: error: 'faX' was not declared in this scope; did you mean 'fa'?
   65 |         num[x]=max(num[x],num[faX[x]]);
      |                               ^~~
      |                               fa
Language: Java

import java.util.Scanner;
import java.awt.Point;
public class Main{
	static boolean r;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Point[] g=new Point[m];
		int[] ans=new int[m];
		ans[m-1]=(n*(n-1))/2;
		for(int i = 0; i<m; i++){
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			g[i]=new Point(a,b);
		}
		Unionfind uf=new Unionfind(n);
		for(int i=m-1; i>=0; i--){
			if(i!=m-1){
				if(!r){
					ans[i]=ans[i+1]-uf.size(g[i+1].x);
				}else{
					ans[i]=ans[i+1];
				}
			}
			r=false;
			uf.unite(g[i].x,g[i].y);
		}
		for(int i = 0; i<m; i++){
			System.out.println(ans[i]);
		}
	}
	static class Unionfind{
		int[] parent;
		int[] ans;
		int[] size;
		public Unionfind(int n){
			this.parent=new int[n];
			this.size=new int[n];
			this.ans=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
				size[i]=1;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				r=ture;
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
			ans[xroot]=size[yroot]*size[xroot];
			size[xroot]+=size[yroot];
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
		public int size(int x){
			return ans[root(x)];
		}
	}
}

Compiler output:
Main.java:55: error: cannot find symbol
				r=ture;
				  ^
  symbol:   variable ture
  location: class Unionfind
1 error
Language: C

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

using namespace std;
struct UnionFind {
    int par[100000]; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    int num[100000];

    UnionFind(void) { //最初は全てが根であるとして初期化
        for(int i = 0; i < 100000; i++) {
            par[i] = i;
            num[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    long long unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        int nx = 0, ny= 0;
        nx = num[rx];
        ny = num[ry];
        //printf("hello");
        if (rx != ry)
        {
            if (nx < ny){
                par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
                num[ry] = nx + ny;
            }
            else
            {
                par[ry] = rx;
                num[rx] = nx + ny;
            }
            return nx * ny;
        }
        else 
        {
            return 0;
        }
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(void)
{
    int n, m;
    int a[100000], b[100000];
    cin >> n >> m;
    for (int i = 0; i < m; i++ ){
        cin >> a[i] >> b[i];
    }


    UnionFind tree;



    long long ans[100000];



    ans[m] = n * (n - 1) / 2;
    for (int i = m - 1; i >= 0; i--)
    {

        ans[i] = ans[i + 1] - tree.unite(a[i], b[i]);

    }


    for (int i = 1; i <= m; i++)
    {
        printf("%lld\n", ans[i]);
    }
    return 0;

}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.