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

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}
ll par[100002];
ll drank[100002];
ll chi[100002];

void init(int n) {
  for(int i = 0; i < n; i++) {
    chi[i] = 1;
    par[i] = i;
    drank[i] = 0;
  }
}

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

void unite(int x, int y) {
  int parx = find(x);
  int pary = find(y);
  if(parx == pary) return;

  if(drank[x] < drank[y]) {
    par[x] = pary;
    chi[pary] += chi[parx];
    chi[parx] = 0;
  }
  else {
    par[y] = parx;
    chi[parx] += chi[pary];
    chi[pary] = 0;
    if(drank[x] == drank[y]) drank[x]++;
  }
}

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


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  int a[100002], b[100002];
  cin >> n >> m;

  ll ans[m+1];
  REP(i, m){
    cin >> a[i] >> b[i];
  }
  ans[m-1] = 1LL * (n * (n - 1) / 2);
  init(n);
  for(int i = m-1; i >= 1; i--) {
    if(same(a[i], b[i])){
      ans[i-1] = 1LL * ans[i];
    }
    else{
      ans[i-1] = 1LL * ans[i] - 1LL * chi[find(a[i])] * chi[find(b[i])]);
      unite(a[i], b[i]);
    }

  }

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

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:101:72: error: expected ';' before ')' token
  101 |       ans[i-1] = 1LL * ans[i] - 1LL * chi[find(a[i])] * chi[find(b[i])]);
      |                                                                        ^
      |                                                                        ;
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(ll i=0;i<n;i++)

struct UnionFind{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> num;

    UnionFind(ll N){
        for(ll i=0;i<N;i++){
            par.push_back(i);
            rank.push_back(0);
            num.push_back(1);
        }
    }

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

    void unite(ll x,ll y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) {
            par[x]=y;
            num[y]+=num[x];
        }else {
            par[y]=x;
            num[x]+=num[y];
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(ll x,ll y){
        return find(x)==find(y);
    }
};

ll main(){
    ll N,M;
    ll A[100000],B[100000];
    cin>>N>>M;
    rep(i,M) cin>>A[i]>>B[i];
    UnionFind T(N);
    vector<ll> ans;
    ans.push_back((N*(N-1))/2);
    ll last;
    rep(i,M){
        last=ans.back();
        if(T.same(A[M-i-1],B[M-i-1])) ans.push_back(last);
        else{
            ans.push_back(last-T.num[T.par[A[M-i-1]]]*T.num[T.par[B[M-i-1]]]);
            T.unite(A[M-i-1],B[M-i-1]);
        }
    }
    ans.pop_back();
    while(!ans.empty()){
        cout<<ans.back()<<endl;
        ans.pop_back();
    }

    return 0;
}

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

class UnionFind {
  public:
  // 親の番号を格納。ルートだった場合は-(その集合のサイズ)
  vector<ll> parents;

  UnionFind(ll N) {
    parents = vector<ll>(N, -1);
  }

  // iがどのグループに属しているか
  ll root(ll i) {
    if (parents[i] < 0) {
      return i;
    } else {
      return parents[i] = root(parents[i]);
    }
  }

  // iが属しているグループの大きさ
  ll size(ll i) {
    return -parents[root(i)];
  }

  // root(a)とroot(b)を接続する
  bool connect(ll a, ll b) {
    ll rootA = root(a);
    ll rootB = root(b);
    if (rootA == rootB) {
        return false;
    } else {
      // 大きいほう(a)に小さいほう(b)をくっつける
      // 大小が逆の場合はスワップ
      if (size(rootA) < size(rootB)) {
        swap(rootA, rootB);
      }

      // aグループのサイズを増やす
      parents[rootA] += parents[rootB];
      // bの親をaのルートに変更する
      parents[rootB] = rootA;

      return true;
    }
  }

};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (ll i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<ll> ans(M);
  // 橋が全部崩落した
  ans[M-1] = N*(N-1)/2;

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

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}
  for (ll i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

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

	UnionFind Uni(N);

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

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

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



Compiler output:
a.cc:92:5: error: redefinition of 'int main()'
   92 | int main() {
      |     ^~~~
a.cc:63:5: note: 'int main()' previously defined here
   63 | int main() {
      |     ^~~~
Language: Java

import java.util.*;
import java.util.stream.*;

public class AtCoder {
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt(), m = scanner.nextInt(), a[] = new int[m], b[] = new int[m], num[] = new int[n + 1];
        long[] ans = new long[m];
        fa = IntStream.rangeClosed(0, n).toArray();
        for (int i = 0; i < m; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        Arrays.fill(num, 1);
        ans[m - 1] = (long)n * (n - 1) / 2;
        for (int i = m - 1; i > 0; i--) {
            ans[i - 1] = ans[i];
            if (fd(a[i]) != fd(b[i])) {
                ans[i - 1] -= num[fa[a[i]]] * num[fa[b[i]]];
                num[fa[b[i]]] += num[fa[a[i]]];
                fa[fa[a[i]]] = fa[b[i]];
            }
        }
        Arrays.stream(ans).forEach(System.out::println);
    }

    static int[] fa;
    static int fd(int a) {
        return fa[a] == a ? a : (fa[a] = fd(fa[a]));
    }
}

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

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<pair<int,int> > e;
  for(int i = 0; i < m; i++){
    int x, y; cin >> x >> y; x--; y--;
    e.push_back({x, y});
  }
  vector<int> uf(n), sz(n);
  for(int i = 0; i < n; i++) uf[i] = i, sz[i] = 1;
  function<(int)int> find = [&](int x){
    if(x == uf[x]) return x;
    return uf[x] = find(uf[x]);
  };
  long long tot = 1ll * n * (n - 1) / 2;
  vector<long long> ans(m);
  for(int i = 0; i < m; i++){
  	int x, y; tie(x, y) = e[i];
    x = find(x);
    y = find(y);
    if(x != y){
    	tot -= 1ll * sz[x] * sz[y];
     	sz[x] += sz[y]; sz[y] = 0;
      	uf[y] = x;
    }
    ans[i] = tot;
  }
  for(int i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
  


Compiler output:
a.cc: In function 'int main()':
a.cc:12:17: error: expected primary-expression before 'int'
   12 |   function<(int)int> find = [&](int x){
      |                 ^~~
a.cc:12:20: error: template argument 1 is invalid
   12 |   function<(int)int> find = [&](int x){
      |                    ^
a.cc: In lambda function:
a.cc:14:24: error: expression cannot be used as a function
   14 |     return uf[x] = find(uf[x]);
      |                    ~~~~^~~~~~~
a.cc: In function 'int main()':
a.cc:12:29: error: cannot convert 'main()::<lambda(int)>' to 'int' in initialization
   12 |   function<(int)int> find = [&](int x){
      |                             ^~~~~~~~~~~
      |                             |
      |                             main()::<lambda(int)>
   13 |     if(x == uf[x]) return x;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~ 
   14 |     return uf[x] = find(uf[x]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 |   };
      |   ~                          
a.cc:20:13: error: 'find' cannot be used as a function
   20 |     x = find(x);
      |         ~~~~^~~
a.cc:21:13: error: 'find' cannot be used as a function
   21 |     y = find(y);
      |         ~~~~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<pair<int,int> > e;
  for(int i = 0; i < m; i++){
    int x, y; cin >> x >> y; x--; y--;
    e.push_back({x, y});
  }
  vector<int> uf(n), sz(n);
  for(int i = 0; i < n; i++) uf[i] = i, sz[i] = 1;
  auto find = [&](int x){
    if(x == uf[x]) return x;
    return uf[x] = find(uf[x]);
  };
  long long tot = 1ll * n * (n - 1) / 2;
  vector<long long> ans(m);
  for(int i = 0; i < m; i++){
  	int x, y; tie(x, y) = e[i];
    x = find(x);
    y = find(y);
    if(x != y){
    	tot -= 1ll * sz[x] * sz[y];
     	sz[x] += sz[y]; sz[y] = 0;
      	uf[y] = x;
    }
    ans[i] = tot;
  }
  for(int i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
  


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

#include <bits/stdc++>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<pair<int,int> > e;
  for(int i = 0; i < m; i++){
    int x, y; cin >> x >> y; x--; y--;
    e.push_back({x, y});
  }
  vector<int> uf(n), sz(n);
  for(int i = 0; i < n; i++) uf[i] = i, sz[i] = 1;
  auto find = [&](int x){
    if(x == uf[x]) return x;
    return uf[x] = find(uf[x]);
  };
  long long tot = 1ll * n * (n - 1) / 2;
  vector<long long> ans(m);
  for(int i = 0; i < m; i++){
  	int x, y; tie(x, y) = e[i];
    x = find(x);
    y = find(y);
    if(x != y){
    	tot -= 1ll * sz[x] * sz[y];
     	sz[x] += sz[y]; sz[y] = 0;
      	uf[y] = x;
    }
    ans[i] = tot;
  }
  for(int i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
  

Compiler output:
a.cc:1:10: fatal error: bits/stdc++: No such file or directory
    1 | #include <bits/stdc++>
      |          ^~~~~~~~~~~~~
compilation terminated.
Language: C++

#include"pch.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define mod 1000000007

ll par[100010][2];

void init(ll n) {
	for (ll i = 0;i < n;i++) {
		par[i][0] = i;
		par[i][1] = 1;
	}
}

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

ll unite(ll x, ll y) {
	ll c = 0;
	x = root(x);
	y = root(y);
	if (x == y) return 0;
	c = par[x][1] * par[y][1];
	if (par[x][1] > par[y][1]) {
		par[y][0] = x;
		par[x][1] += par[y][1];
	} else {
		par[x][0] = y;
		par[y][1] += par[x][1];
	}
	return c;
}

int main() {
	int N, M; cin >> N >> M;
	vector<pair<ll, ll>> Br(M);
	ll a, b;
	for (int i = 0;i < M;i++) {
		cin >> a >> b;
		Br[i] = {a,b};
	}
	init(N);
	vector<ll> ls(M,0);
	ll ans=0;
	ll ac = 1LL * N * (N - 1) / 2;
	for (int i = 0;i < M;i++) {
		ls[M-1-i] = ac - ans;
		ans += unite(Br[M-1-i].first,Br[M-1-i].second);
	}
	for (int i = 0;i < M;i++)
		cout << ls[i] << endl;
}

Compiler output:
a.cc:1:9: fatal error: pch.h: No such file or directory
    1 | #include"pch.h"
      |         ^~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<long long> par; 
    vector<long long> n;

    UnionFind(long long N) : par(N),n(N) {
        for(long long i = 0; i < N; i++) {par[i] = i;n[i]=1;}
    }
 
    long long root(long long x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(long long x, long long y) { 
        long long rx = root(x);
        long long ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        n[ry]+=n[rx];
    }
    bool same(long long x, long long y) {
        long long rx = root(x);
        long long ry = root(y);
        return rx == ry;
    }
    long long count(long long x){
        return n[root(x)];
    }
};
long long main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N,M;
    cin>>N>>M;
    UnionFind tree(N);
    vector<long long>A(M),B(M);
    for(long long i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--,B[i]--;
    }
    vector<long long>sub(M);
    long long num = N*(N-1)/2;
    for(long long i=M-1;i>=0;i--){
        sub[i]=num;
        if(!tree.same(A[i],B[i])){
            num-=tree.count(A[i])*tree.count(B[i]);
        }
        tree.unite(A[i],B[i]);
    }
    for(long long i=0;i<M;i++){
        cout<<sub[i]<<endl;
    }
}

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct UnionFind{
  vi data;
  UnionFind(int N): data(N,-1) {}

  int find(int x){
    if (data[x]<0){return x;}
    else{
      return find(data[x]);
    }
  }
  
  void unite(int x, int y){
    x=find(x);y=find(y);
    if(data[x]>data[y]){swap(x,y);}
    data[x]+=data[y];
    data[y]=x;
  }

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

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

int main(){
  int N,M;cin>>N>>M;
  int A, B;
  
  for (int i=0;i<N;++i){
    int a,b;cin>>a>>b;
    A.push_back(a-1);B.push_back(b-1);
  }

  UnionFind tree(N);

  vll ans(M);
  ll inconvenience=N*(N-1)/2;
  for (int i=M-1;i>=0;--i){
    ans[i]=inconvenience;
    int sa=size(A[i]);int sb=size(B[i]);
    inconvenience+=sa*(sa-1)/2+sb*(sb-1)/2;
    unite(A[i], B[i]);
    int s=size(A[i]);
    inconvenience-=s*(s-1)/2;
  }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:37:7: error: request for member 'push_back' in 'A', which is of non-class type 'int'
   37 |     A.push_back(a-1);B.push_back(b-1);
      |       ^~~~~~~~~
a.cc:37:24: error: request for member 'push_back' in 'B', which is of non-class type 'int'
   37 |     A.push_back(a-1);B.push_back(b-1);
      |                        ^~~~~~~~~
a.cc:46:18: error: invalid types 'int[int]' for array subscript
   46 |     int sa=size(A[i]);int sb=size(B[i]);
      |                  ^
a.cc:46:36: error: invalid types 'int[int]' for array subscript
   46 |     int sa=size(A[i]);int sb=size(B[i]);
      |                                    ^
a.cc:48:12: error: invalid types 'int[int]' for array subscript
   48 |     unite(A[i], B[i]);
      |            ^
a.cc:48:18: error: invalid types 'int[int]' for array subscript
   48 |     unite(A[i], B[i]);
      |                  ^
a.cc:48:5: error: 'unite' was not declared in this scope
   48 |     unite(A[i], B[i]);
      |     ^~~~~
a.cc:49:17: error: invalid types 'int[int]' for array subscript
   49 |     int s=size(A[i]);
      |                 ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

struct UnionFind{
  vi data;
  UnionFind(int N): data(N, -1){ }

  int root(int x){
    if(data[x]<0){return x;}
    else{return root(data[x]);}
  }
  
  int size(int x){return -data[root(x)];}
  
  void unite(int x, int y){
    x=root(x);y=root(y);
    if(x!=y){
      if(data[x]>data[y]){swap(x,y);}
      data[x]+=data[y];
      data[y]=x;
    }
  }
};

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

int main(){
  int N, M;cin>>N>>M;
  vi a, b;
  for (int i=0;i<M;++i){
    int a_, b_;cin>>a_>>b_;
    a.push_back(a_-1);
    b.push_back(b_-1);
  }

  vll ans(M);
  ll incombeniency=n_pairs(N);
  UnionFind uf(N);

  for (int i=M-1;i>=0;--i){
    ans[i]=incombeniency;
    int ra=uf.root(a[i]);int rb=uf.root(b[i]);
    if(ra!=rb){
      int sa=uf.size(ra);int sb=uf.size(rb);
      incombeniency+=n_pairs(sa)+n_pairs(sb);
      uf.unite(a[i], b[i]);
      r=uf.root(a[i]);s=uf.size(r);
      incombeniency-=n_pairs(s);
    }
  }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:50:7: error: 'r' was not declared in this scope; did you mean 'rb'?
   50 |       r=uf.root(a[i]);s=uf.size(r);
      |       ^
      |       rb
a.cc:50:23: error: 's' was not declared in this scope; did you mean 'sb'?
   50 |       r=uf.root(a[i]);s=uf.size(r);
      |                       ^
      |                       sb
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

struct UnionFind{
  vi data;
  UnionFind(int N) data(N, -1), count(N){ }

  int root(int x){
    if(data[x]<0){return x;}
    else{return root(data[x]);}
  }
  
  int size(int x){return -data[root(x)];}
  
  void unite(int x, int y){
    x=root(x);y=root(y);
    if(x!=y){
      if(data[x]>data[y]){swap(x,y);}
      data[x]+=data[y];
      data[y]=x;
    }
  }
};

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

int main(){
  int N, M;cin>>N>>M;
  vi a, b;
  for (int i=0;i<M;++i){
    int a_, b_;cin>>a_>>b_;
    a.push_back(a_-1);
    b.push_back(b_-1);
  }

  vll ans(M);
  ll incombeniency=n_pairs(N);
  UnionFind uf(N);

  for (int i=M-1;i>=0;--i){
    ans[i]=incombeniency;
    int ra=uf.root(a[i]);int rb=uf.root(b[i]);
    if(ra!=rb){
      int sa=uf.size(ra);int sb=uf.size(rb);
      incombeniency+=n_pairs(sa)+n_pairs(sb);
      uf.unite(a[i], b[i]);
      r=uf.root(a[i]);s=uf.size(r);
      incombeniency-=n_pairs(s);
    }
  }

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

Compiler output:
a.cc:9:18: error: expected ';' at end of member declaration
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                  ^
      |                   ;
a.cc:9:25: error: 'N' has not been declared
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                         ^
a.cc:9:28: error: expected identifier before '-' token
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                            ^
a.cc:9:28: error: expected ',' or '...' before '-' token
a.cc:9:20: error: ISO C++ forbids declaration of 'data' with no type [-fpermissive]
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                    ^~~~
a.cc:9:31: error: 'int UnionFind::data(int, int)' conflicts with a previous declaration
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                               ^
a.cc:8:6: note: previous declaration 'vi UnionFind::data'
    8 |   vi data;
      |      ^~~~
a.cc:9:39: error: 'N' has not been declared
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                                       ^
a.cc:9:33: error: ISO C++ forbids declaration of 'count' with no type [-fpermissive]
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                                 ^~~~~
a.cc: In member function 'int UnionFind::count(int)':
a.cc:9:43: warning: no return statement in function returning non-void [-Wreturn-type]
    9 |   UnionFind(int N) data(N, -1), count(N){ }
      |                                           ^
a.cc: In function 'int main()':
a.cc:50:7: error: 'r' was not declared in this scope; did you mean 'rb'?
   50 |       r=uf.root(a[i]);s=uf.size(r);
      |       ^
      |       rb
a.cc:50:23: error: 's' was not declared in this scope; did you mean 'sb'?
   50 |       r=uf.root(a[i]);s=uf.size(r);
      |                       ^
      |                       sb
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

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

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

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

  void unite(int x, int y){
    x=find(x);y=find(y);
    if(x==y){return;}
    else{
      if(rank[x]<rank[y]){par[x]=y;}
      else{
        par[y]=x;
        if(rank[x]==rank[y]){rank[x]++;}
      }
      num_members[x]+=num_members[y];
      num_members[y]+=num_members[x];
    }
  }

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

//一つのグループ内で行き来できる島の数
ll num_pairs(int n){
  return (ll)n*(n-1)/2;
}


int main(){
  //入力の受け取り
  int N, M;cin>>N>>M;
  vi A,B;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;
    A.push_back(a);B.push_back(b);
  }

  //橋がない、M-1th, M-2th,...,0thまで繋がっている時にいくつの島が繋がっているか
  
  UnionFind uf(N);
  vll ans(M);
  ll curr = num_pairs(N);
  for (int i=M-1; i>=0; --i){
    ans[i] = curr;
    int ra=uf.root(A[i]), rb=uf.root(B[i]);
    if (ra != rb) {
      int sa=uf.size(ra), sb=uf.size(rb);
      curr += num_pairs(sa) + num_pairs(sb);
      uf.unite(A[i], B[i]);
      int r=uf.root(A[i]);
      int s=uf.size(r);
      curr -= num_pairs(s);
    }
  }

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

  return 0;
}


Compiler output:
a.cc:25:8: error: redefinition of 'struct UnionFind'
   25 | struct UnionFind{
      |        ^~~~~~~~~
a.cc:7:8: note: previous definition of 'struct UnionFind'
    7 | struct UnionFind {
      |        ^~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

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

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

  void unite(int x, int y){
    x=find(x);y=find(y);
    if(x==y){return;}
    else{
      if(rank[x]<rank[y]){par[x]=y;}
      else{
        par[y]=x;
        if(rank[x]==rank[y]){rank[x]++;}
      }
      num_members[x]+=num_members[y];
      num_members[y]+=num_members[x];
    }
  }

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

//一つのグループ内で行き来できる島の数
ll num_pairs(int n){
  return (ll)n*(n-1)/2;
}


int main(){
  //入力の受け取り
  int N, M;cin>>N>>M;
  vi A,B;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;
    A.push_back(a);B.push_back(b);
  }

  //橋がない、M-1th, M-2th,...,0thまで繋がっている時にいくつの島が繋がっているか
  
  UnionFind uf(N);
  vll ans(M);
  ll curr = num_pairs(N);
  for (int i=M-1; i>=0; --i){
    ans[i] = curr;
    int ra=uf.find(A[i]), rb=uf.find(B[i]);
    if (ra != rb) {
      int sa=uf.num_members(ra), sb=uf.num_members(rb);
      curr += num_pairs(sa) + num_pairs(sb);
      uf.unite(A[i], B[i]);
      int r=uf.find(A[i]);
      int s=uf.num_members(r);
      curr -= num_pairs(s);
    }
  }

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

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:28: error: no match for call to '(vi {aka std::vector<int>}) (int&)'
   65 |       int sa=uf.num_members(ra), sb=uf.num_members(rb);
      |              ~~~~~~~~~~~~~~^~~~
a.cc:66:41: error: 'sb' was not declared in this scope; did you mean 'sa'?
   66 |       curr += num_pairs(sa) + num_pairs(sb);
      |                                         ^~
      |                                         sa
a.cc:69:27: error: no match for call to '(vi {aka std::vector<int>}) (int&)'
   69 |       int s=uf.num_members(r);
      |             ~~~~~~~~~~~~~~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

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

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

  void unite(int x, int y){
    x=find(x);y=find(y);
    if(x==y){return;}
    else{
      if(rank[x]<rank[y]){par[x]=y;}
      else{
        par[y]=x;
        if(rank[x]==rank[y]){rank[x]++;}
      }
      num_members[x]+=num_members[y];
      num_members[y]+=num_members[x];
    }
  }

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

//一つのグループ内で行き来できる島の数
ll num_pairs(int n){
  return (ll)n*(n-1)/2;
}


int main(){
  //入力の受け取り
  int N, M;cin>>N>>M;
  vi A,B;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;
    A.push_back(a);B.push_back(b);
  }

  //橋がない、M-1th, M-2th,...,0thまで繋がっている時にいくつの島が繋がっているか
  
  UnionFind uf(N);
  vll ans(M);
  ll curr = num_pairs(N);
  for (int i=M-1; i>=0; --i){
    ans[i] = curr;
    int ra=uf.find(a[i]), rb=uf.find(b[i]);
    if (ra != rb) {
      int sa=uf.num_members(ra), sb=uf.num_members(rb);
      curr += num_pairs(sa) + num_pairs(sb);
      uf.unite(a[i], b[i]);
      int r=uf.find(a[i]);
      int s=uf.num_members(r);
      curr -= num_pairs(s);
    }
  }

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

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:63:20: error: 'a' was not declared in this scope
   63 |     int ra=uf.find(a[i]), rb=uf.find(b[i]);
      |                    ^
a.cc:64:15: error: 'rb' was not declared in this scope; did you mean 'ra'?
   64 |     if (ra != rb) {
      |               ^~
      |               ra
a.cc:65:28: error: no match for call to '(vi {aka std::vector<int>}) (int&)'
   65 |       int sa=uf.num_members(ra), sb=uf.num_members(rb);
      |              ~~~~~~~~~~~~~~^~~~
a.cc:66:41: error: 'sb' was not declared in this scope; did you mean 'sa'?
   66 |       curr += num_pairs(sa) + num_pairs(sb);
      |                                         ^~
      |                                         sa
a.cc:67:22: error: 'b' was not declared in this scope
   67 |       uf.unite(a[i], b[i]);
      |                      ^
a.cc:69:27: error: no match for call to '(vi {aka std::vector<int>}) (int&)'
   69 |       int s=uf.num_members(r);
      |             ~~~~~~~~~~~~~~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct UnionFind{
  vi par;
  vi rank;
  vi num_members;
  UnionFInd(int N): par(N), rank(N), num_members(N) {
    for (int i=0;i<N;++i){
      par[i]=i;
      rank[i]=0;
      num_members[i]=1;
    }
  }

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

  void unite(int x, int y){
    x=find(x);y=find(y);
    if(x==y){return;}
    else{
      if(rank[x]<rank[y]){par[x]=y;}
      else{
        par[y]=x;
        if(rank[x]==rank[y]){rank[x]++;}
      }
      num_members[x]+=num_members[y];
      num_members[y]+=num_members[x];
    }
  }

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

//一つのグループ内で行き来できる島の数
ll num_pairs(int n){
  return (ll)n*(n-1)/2;
}


int main(){
  //入力の受け取り
  int N, M;cin>>N>>M;
  vi A,B;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;
    A.push_back(a);B.push_back(b);
  }

  //橋がない、M-1th, M-2th,...,0thまで繋がっている時にいくつの島が繋がっているか
  vll num_connected_pairs;

  ll count=0;
  num_connected_pairs.push_back(count);
  UnionFind uf(N);

  for (int i=M-1;i>=0;--i){
    int x=uf.find(A[i]);int y=uf.find(B[i]);
    if (x==y){
      num_connected_pairs.push_back(count);
    }
    else{
      int n=uf.num_members[x];int m=uf.num_members[y];
      uf.unite(A[i],B[i]);
      int x=uf.find(A[i]);
      int l=uf.num_members[x];
      count+=num_pairs(l)-num_pairs(n)-num_pairs(m);
      //ここでpush_backされた値は、M-1st--ithまでの(M-i)この橋があるとき。　
      num_connected_pairs.push_back(count);
    }
  }

  //今いくつ不便になった？
  vll incombeniency;
  for (int i=M-1;i>=0;--i){
    ll a=num_connected_pairs[M]-num_connected_pairs[i];
    incombeniency.push_back(a);
  }

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


Compiler output:
a.cc:11:3: error: ISO C++ forbids declaration of 'UnionFInd' with no type [-fpermissive]
   11 |   UnionFInd(int N): par(N), rank(N), num_members(N) {
      |   ^~~~~~~~~
a.cc: In member function 'int UnionFind::UnionFInd(int)':
a.cc:11:21: error: only constructors take member initializers
   11 |   UnionFInd(int N): par(N), rank(N), num_members(N) {
      |                     ^~~
a.cc:17:3: warning: no return statement in function returning non-void [-Wreturn-type]
   17 |   }
      |   ^
a.cc: In function 'int main()':
a.cc:61:17: error: no matching function for call to 'UnionFind::UnionFind(int&)'
   61 |   UnionFind uf(N);
      |                 ^
a.cc:7:8: note: candidate: 'UnionFind::UnionFind()'
    7 | struct UnionFind{
      |        ^~~~~~~~~
a.cc:7:8: note:   candidate expects 0 arguments, 1 provided
a.cc:7:8: note: candidate: 'UnionFind::UnionFind(const UnionFind&)'
a.cc:7:8: note:   no known conversion for argument 1 from 'int' to 'const UnionFind&'
a.cc:7:8: note: candidate: 'UnionFind::UnionFind(UnionFind&&)'
a.cc:7:8: note:   no known conversion for argument 1 from 'int' to 'UnionFind&&'
Language: C++

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <vector>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define vec vector<int>
#define vecll vector<ll>
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
struct UnionFind{
    vec par,size;
    UnionFind(int n):par(n),size(n){
        rep(i,n){
            par[i]=i;
            size[i]=1;
        }
    }
    int root(int x){
        if(par[x]==x)return x;
        return root(par[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry)return;
        par[rx]=ry;
        size[ry]+=size[rx];
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
};
int main(){
    ll n=lin();
    int m=in();
    UnionFind tree(n);
    vecll a(m),b(m),ans(m);
    ans[m-1]=0;
    rep(i,m){
        a[i]=in()-1;
        b[i]=in()-1;
    }
    rep3(i,m-2,0){
        if(!tree.same(a[i+1],b[i+1])){
            ans[i]=ans[i+1]+tree.size[root(a[i+1])]*tree.size[root(b[i+1])];
            tree.unite(a[i+1],b[i+1]);
        }else ans[i]=ans[i+1];
    }
    ll k=n*(n-1)/2;
    rep(i,m)cout<<k-ans[i]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:39: error: 'root' was not declared in this scope
   61 |             ans[i]=ans[i+1]+tree.size[root(a[i+1])]*tree.size[root(b[i+1])];
      |                                       ^~~~
Language: C++

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <vector>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define vec vector<int>
#define vecll vector<ll>
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
struct UnionFind{
    vec par,size;
    UnionFind(int n) : par(n),size(n){
        reo(i,n){
            par[i]=i;
            size[i]=1;
        }
    }
    int root(int x){
        if(par[x]==x)return x;
        return root(par[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry)return;
        par[rx]=ry;
        size[ry]+=size[rx];
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int getSize(int x){
        return size[root(x)];
    }
};
int main(){
    ll n=lin(),m=in();
    UnionFind tree(n);
    vecll a(n),b(n),ans(m);
    ans[m-1]=0;
    rep(i,m){
        a[i]=in()-1;
        b[i]=in()-1;
    }
    rep3(i, m-2, 0){
        int x=a[i+1],y=b[i+1];
        if(!tree.same(x,y)){
            ans[i]=ans[i+1]+tree.getSize(x)*tree.getSize(y);
            tree.unite(x,y);
        }else ans[i]=ans[i+1];
    }
    ll k=n*(n-1)/2;
    rep(i,m)cout<<k-ans[i]<<endl;
}

Compiler output:
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:29:13: error: 'i' was not declared in this scope; did you mean 'in'?
   29 |         reo(i,n){
      |             ^
      |             in
a.cc:29:9: error: 'reo' was not declared in this scope; did you mean 'rep'?
   29 |         reo(i,n){
      |         ^~~
      |         rep
Language: Java

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Solution {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskDecayed solver = new TaskDecayed();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskDecayed {
        public static TaskDecayed.V[] vertices;
        public static TaskDecayed.E[] edges;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            vertices = new TaskDecayed.V[N];
            edges = new TaskDecayed.E[M];
            for (int i = 0; i < N; i++) {
                vertices[i] = new TaskDecayed.V(i + 1);
            }
            for (int i = 0; i < M; i++) {
                edges[i] = new TaskDecayed.E(in.nextInt(), in.nextInt(), i);
            }

            long res[] = new long[M + 1];
            res[M] = N * (N - 1) / 2;
            for (int i = M - 1; i >= 0; i--) {
                res[i] = res[i + 1] - union(edges[i].v1, edges[i].v2);
            }
            if (res[0] != 0)
                throw new RuntimeException("Diff");
            for (int i = 1; i <= M; i++) {
                out.println(res[i]);
            }
        }

        private long union(TaskDecayed.V v1, TaskDecayed.V v2) {
            TaskDecayed.V rootV1 = findRoot(v1);
            TaskDecayed.V rootV2 = findRoot(v2);
            if (rootV1 == rootV2)
                return 0;
            if (rootV1.rank < rootV2.rank) {
                TaskDecayed.V tmp = rootV1;
                rootV1 = rootV2;
                rootV2 = tmp;
            }
            long res = rootV1.nb * rootV2.nb;
            rootV1.parent = rootV2;
            rootV2.nb += rootV1.nb;
            return res;
        }

        private TaskDecayed.V findRoot(TaskDecayed.V v) {
            if (v.parent == null)
                return v;
            v.parent = findRoot(v.parent);
            return v.parent;
        }

        public static class V {
            int id;
            int rank;
            int nb;
            TaskDecayed.V parent;

            public V(int id) {
                this.id = id;
                this.rank = 1;
                this.nb = 1;
            }

        }

        public static class E {
            TaskDecayed.V v1;
            TaskDecayed.V v2;
            int id;

            public E(int id1, int id2, int id) {
                this.v1 = vertices[id1 - 1];
                this.v2 = vertices[id2 - 1];
                this.id = id;
            }

        }

    }
}



Compiler output:
Main.java:11: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
1 error
Language: Java

import java.util.*;
public class decayedbridges {
	
	public static class unionfind{
		int[] parent;
		int[] rank;
		int[] number;
		public unionfind(int n){
			this.parent = new int[n+1];
			this.rank = new int[n+1];
			this.number = new int[n+1];
			for(int i = 1; i <= n; i++) set(i);
		}
		public void set(int i) {
			parent[i] = i;
			rank[i] = 0;
			number[i] = 1;
		}
		public int find(int i) {
			if (i == parent[i])
				return parent[i];
			else
				return parent[i] = find(parent[i]);
			
		}
		public boolean same(int x, int y){
			return find(x) == find(y);
		}
		public void unite(int x, int y) {
			int xroot = find(x);
			int yroot = find(y);
			if(xroot == yroot)
				return;
			if(rank[xroot] > rank[yroot]) {
				parent[yroot] = xroot;
				number[xroot] += number[yroot];
			}
			else if(rank[xroot] < rank[yroot]) {
				parent[xroot] = yroot;
				number[yroot] += number[xroot];
			}
			else {
				parent[yroot] = xroot;
				number[xroot] += number[yroot];
				rank[xroot]++;
			}
		}
		public int getnumber(int i) {
			return number[find(i)];
		}
	}
	
	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();
		}
		unionfind u = new unionfind(n);
		long[] ans = new long[m+1];
		ans[m] = n*(n-1)/2;
		if(m != 1) {
			for(int i = m-1; i >= 0; i--) {
				if(u.same(A[i], B[i])) {
					ans[i] = ans[i+1];
				}
				else{
					ans[i] = ans[i+1] - u.getnumber(A[i])*u.getnumber(B[i]);
					u.unite(A[i], B[i]);
				}
			}
		}
		for(int i = 1; i <= m; i++) {
			System.out.println(ans[i]);
		}
	}
}

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

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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 (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
    vector<ll> par, rank;
 
    UnionFind(ll n) : par(n , -1), rank(n, 0) { }
    void init(ll n) { par.assign(n, -1), rank.assign(n, 0); }
 
    int root(ll x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
 
    bool merge(ll x, ll y) {
        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;
        return true;
    }
};
 
int main(){
    ll N,M;
  	cin >> N >> M;
  	vector<ll> A(M), B(M);
  	rep(i,M){
      cin >> A[i] >> B[i];
      A[i]--;
      B[i]--;
    }
  
  	vector<ll> ans(M);
  	ans[M-1] = N * (N - 1) / 2;
  
  	UnionFind Uni(N);
  
  	reprev(i, M - 1){
      //繋がってなかったのが繋がった時
      	if(Uni.root(A[i]) != Uni.root(B[i])){
          ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
          Uni.merge(A[i],B[i]);
        }
      else ans[i - 1] = ans[i]; 
    }
  
  rep(i,M){
    cout << ans[i] << endl;
  }
  	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:91:37: error: 'struct UnionFind' has no member named 'size'
   91 |           ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      |                                     ^~~~
a.cc:91:54: error: 'struct UnionFind' has no member named 'size'
   91 |           ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      |                                                      ^~~~
Language: C++

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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 (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<ll> par, rank;

    UnionFind(ll n) : par(n , -1), rank(n, 0) { }
    void init(ll n) { par.assign(n, -1), rank.assign(n, 0); }

    int root(ll x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(ll x, ll y) {
        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;
        return true;
    }
};

int main(){
    ll N,M;
  	cin >> N >> M;
  	vector<ll> A(M), B(M);
  	rep(i,M){
      cin >> A[i] >> B[i];
    }
  
  	vector<ll> ans(M);
  	ans[M-1] = N * (N - 1) / 2;
  
  	UnionFind Uni(N);
  
  	reprev(i, M - 1){
      //繋がってなかったのが繋がった時
      	if(Uni.root(A[i]) != Uni.root(B[i])){
          ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
          Uni.merge(A[i],B[i]);
        }
      else ans[i - 1] = ans[i]; 
    }
  
  rep(i,M){
    cout << ans[i] << endl;
  }
  	
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:37: error: 'struct UnionFind' has no member named 'size'
   89 |           ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      |                                     ^~~~
a.cc:89:54: error: 'struct UnionFind' has no member named 'size'
   89 |           ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
      |                                                      ^~~~
Language: C++

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if ONLINE_JUDGE
#define tr(...)
#define endl '\n'
#else
#include "../../tr.h"
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n, a[N];

struct UnionFind
{
   vector<int> A, S;

   UnionFind(int n){
      A.resize(n+1);
      S.resize(n+1);
      for (int i = 1; i <= n; ++i)
      {
         A[i] = i;
         S[i] = 1;         
      }
   }

   int find(int x){
      while(x != A[x]){
         A[x] = A[A[x]];
         x = A[x];
      }
      return x;
   }

   bool unite(int x, int y){
      x = find(x), y = find(y);
      if(x == y)
         return false;
      if(S[x] < S[y])swap(x, y);
      S[x] += S[y];
      A[y] = x;
      return true;
   } 
};

int m;
vector<P> queries;

int32_t main(){_

   cin>>n>>m;
   UnionFind S(n);

   for (int i = 0; i < m; ++i)
   {
      int x, y;
      cin>>x>>y;
      queries.pb({x, y});
   }

   int ans = n*(n-1) / 2;
   reverse(queries.begin(), queries.end());

   vector<int> store;
   store.pb(ans);

   for(auto it: queries){
      int x = it.F, y = it.S;
      x = S.find(x), y = S.find(y);
      if(x == y){
         store.pb(ans);
         continue;
      }

      int S1 = S.S[x], S2 = S.S[y];

      int A = ((S1 + S2)*((S1 + S2 - 1))) / 2;
      int B = (S1*(S1-1))/2 + (S2*(S2-1))/2;

      ans -= (A-B);
      S.unite(x, y);
      store.pb(ans);
   }

   store.pop_back();
   reverse(store.begin(), store.end());

   for(auto it: store)
      cout<<it<<'\n';

   #warning make sure N size is correct!
   return 0;
}

Compiler output:
a.cc:17:10: fatal error: ../../tr.h: No such file or directory
   17 | #include "../../tr.h"
      |          ^~~~~~~~~~~~
compilation terminated.