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

#include<bits/stdc++.h>
using namespace std;
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  Union qwerty(n);
  vector<int> x(m),y(m),z(m);
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i] >> z[i];
    qwrety.unite(x[i],y[i]);
  }
  set<int> q;
  for(int i=0;i<n;i++){
    q=qwerty.find(i);
  }
  cout << q.size() << endl;;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:5: error: 'qwrety' was not declared in this scope; did you mean 'qwerty'?
   40 |     qwrety.unite(x[i],y[i]);
      |     ^~~~~~
      |     qwerty
a.cc:44:20: error: no match for 'operator=' (operand types are 'std::set<int>' and 'int')
   44 |     q=qwerty.find(i);
      |                    ^
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_set.h:300:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(const std::set<_Key, _Compare, _Alloc>&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  300 |       operator=(const set&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:300:17: note:   no known conversion for argument 1 from 'int' to 'const std::set<int>&'
  300 |       operator=(const set&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::set<_Key, _Compare, _Alloc>&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  304 |       operator=(set&&) = default;
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:304:17: note:   no known conversion for argument 1 from 'int' to 'std::set<int>&&'
  304 |       operator=(set&&) = default;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_set.h:318:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  318 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_set.h:318:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  318 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  Union qwerty(n);
  vector<int> x(m),y(m),z(m);
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i] >> z[i];
    qwrety.unite(x[i],y[i]);
  }
  set<int> q;
  for(int i=0;i<n;i++){
    q=qwrety.find(i);
  }
  cout << q.size() << endl;;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:5: error: 'qwrety' was not declared in this scope; did you mean 'qwerty'?
   40 |     qwrety.unite(x[i],y[i]);
      |     ^~~~~~
      |     qwerty
a.cc:44:7: error: 'qwrety' was not declared in this scope; did you mean 'qwerty'?
   44 |     q=qwrety.find(i);
      |       ^~~~~~
      |       qwerty
Language: C++

#include<bits/stdc++.h>
using namespace std;
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  Union qwerty(n);
  vector<int> x(m),y(m),z(m);
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i] >> z[i];
    qwrety.unite(x[i],y[i]);
  }
  set<int> q;
  for(int i=0;i<n;i++){
    q=find(i);
  }
  cout << q.size() << endl;;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:5: error: 'qwrety' was not declared in this scope; did you mean 'qwerty'?
   40 |     qwrety.unite(x[i],y[i]);
      |     ^~~~~~
      |     qwerty
a.cc:44:11: error: no matching function for call to 'find(int&)'
   44 |     q=find(i);
      |       ~~~~^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
Language: Java

import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String args[]){
  	Scanner scan = new Scanner(System.in);
    String str;
    Long n, m;
    Long len = 0;
    ArrayList<Long> x = new ArrayList<Long>();
    ArrayList<Long> y = new ArrayList<Long>();
    Long result = 0;
    
    while(scan.hasNextLine()){
      len++;
      str = scan.next();
      if(count == 0){
        String[] nums = str.split(" ");
        n = Long.parseLong(nums[0]);
        m = Long.parseLong(nums[1]);
      }else{
      	String[] nums = str.split(" ");
        x.add(Long.parseLong(nums[0]));
        y.add(Long.parseLong(nums[1]));
      }
    }
    
    int input[][] = new int[max][3];
    
    for(int i = 0; i < max; i++){
      input[i][0] = x.get(i);
      input[i][1] = y.get(i);
      input[i][2] = 0;
    }
    
    for(int i = 0; i < max; i++){
      if(input[i][2] != 1){
        Long tmp = input[i][0];
        for(int j = i + 1; j < max; j++){
          if(input[j][0] == tmp || input[j][1] == tmp){
          	input[j][2] = 1;
          }
        }
      }
      result++;
    }
    System.out.println(result);
  }
}


Compiler output:
Main.java:9: error: incompatible types: int cannot be converted to Long
    Long len = 0;
               ^
Main.java:12: error: incompatible types: int cannot be converted to Long
    Long result = 0;
                  ^
Main.java:17: error: cannot find symbol
      if(count == 0){
         ^
  symbol:   variable count
  location: class Main
Main.java:28: error: cannot find symbol
    int input[][] = new int[max][3];
                            ^
  symbol:   variable max
  location: class Main
Main.java:30: error: cannot find symbol
    for(int i = 0; i < max; i++){
                       ^
  symbol:   variable max
  location: class Main
Main.java:31: error: incompatible types: Long cannot be converted to int
      input[i][0] = x.get(i);
                         ^
Main.java:32: error: incompatible types: Long cannot be converted to int
      input[i][1] = y.get(i);
                         ^
Main.java:36: error: cannot find symbol
    for(int i = 0; i < max; i++){
                       ^
  symbol:   variable max
  location: class Main
Main.java:38: error: incompatible types: int cannot be converted to Long
        Long tmp = input[i][0];
                           ^
Main.java:39: error: cannot find symbol
        for(int j = i + 1; j < max; j++){
                               ^
  symbol:   variable max
  location: class Main
10 errors
Language: Java

import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String args[]){
  	Scanner scan = new Scanner(System.in);
    String str;
    Long n, m;
    Long len = 0;
    ArrayList<Long> x = new ArrayList<Long>();
    ArrayList<Long> y = new ArrayList<Long>();
    Long result = 0;
    
    while(scan.hasNextLine()){
      len++;
      str = scan.next();
      if(count == 0){
        String[] nums = str.split(" ");
        n = Long.parseLong(nums[0]);
        m = Long.parseLong(nums[1]);
      }else{
      	String[] nums = str.split(" ");
        x.add(Long.parseLong(nums[0]));
        y.add(Long.parseLong(nums[1]));
        z.add(Long.parseLong(nums[2]));
      }
    }
    
    int input[][] = new int[max][3];
    
    for(int i = 0; i < max; i++){
      input[i][0] = x.get(i);
      input[i][1] = y.get(i);
      input[i][2] = 0;
    }
    
    for(int i = 0; i < max; i++){
      if(input[i][2] != 1){
        Long tmp = input[i][0];
        for(int j = i + 1; j < max; j++){
          if(input[j][0] == tmp || input[j][1] == tmp){
          	input[j][2] = 1;
          }
        }
      }
      result++;
    }
    System.out.println(result);
  }
}


Compiler output:
Main.java:9: error: incompatible types: int cannot be converted to Long
    Long len = 0;
               ^
Main.java:12: error: incompatible types: int cannot be converted to Long
    Long result = 0;
                  ^
Main.java:17: error: cannot find symbol
      if(count == 0){
         ^
  symbol:   variable count
  location: class Main
Main.java:25: error: cannot find symbol
        z.add(Long.parseLong(nums[2]));
        ^
  symbol:   variable z
  location: class Main
Main.java:29: error: cannot find symbol
    int input[][] = new int[max][3];
                            ^
  symbol:   variable max
  location: class Main
Main.java:31: error: cannot find symbol
    for(int i = 0; i < max; i++){
                       ^
  symbol:   variable max
  location: class Main
Main.java:32: error: incompatible types: Long cannot be converted to int
      input[i][0] = x.get(i);
                         ^
Main.java:33: error: incompatible types: Long cannot be converted to int
      input[i][1] = y.get(i);
                         ^
Main.java:37: error: cannot find symbol
    for(int i = 0; i < max; i++){
                       ^
  symbol:   variable max
  location: class Main
Main.java:39: error: incompatible types: int cannot be converted to Long
        Long tmp = input[i][0];
                           ^
Main.java:40: error: cannot find symbol
        for(int j = i + 1; j < max; j++){
                               ^
  symbol:   variable max
  location: class Main
11 errors
Language: C++

#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
const int M=1e6+5;
const int INF=0x3f3f3f3f;
const ull sed=31;
const ll mod=1e9+7;
const double eps=1e-9;
typedef pair<int,int>P;
typedef pair<double,double>Pd;

int n,m,ans;
bool vis[N];
vector<int>E[N];

void dfs(int x)
{
    if(vis[x]) return ;
    vis[x]=true;
    for(int i=0;i<E[x].size();i++) dfs(E[x][i]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) line[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        E[x].push_back(y);
        E[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[x]) continue;
        ans++;
        dfs(x);
    }
    printf("%d\n",ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:27: error: 'line' was not declared in this scope; did you mean 'link'?
   28 |     for(int i=1;i<=n;i++) line[i]=i;
      |                           ^~~~
      |                           link
a.cc:38:16: error: 'x' was not declared in this scope
   38 |         if(vis[x]) continue;
      |                ^
a.cc:40:13: error: 'x' was not declared in this scope
   40 |         dfs(x);
      |             ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int n,m;

int p[100005];
int find(int x){
	if(x!=p[x])
	  p[x]=find(p[x]);
	return p[x];
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	int a,b,c,f_a,f_b,ans=0;
	while(m--){
		cin>>a>>b>>c;
		f_a=find(a);
		f_b=find(b);
		if(f_a!=f_b)
		  p[f_a]=f_b;
	}
	for(int i=1;i<=100005;i++)
	   if(i==p[i])
	     ans++ ;
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:22: error: 'a' was not declared in this scope
   16 |                 cin>>a>>b>>c;
      |                      ^
a.cc:16:25: error: 'b' was not declared in this scope
   16 |                 cin>>a>>b>>c;
      |                         ^
a.cc:16:28: error: 'c' was not declared in this scope
   16 |                 cin>>a>>b>>c;
      |                            ^
a.cc:17:17: error: 'f_a' was not declared in this scope; did you mean 'fma'?
   17 |                 f_a=find(a);
      |                 ^~~
      |                 fma
a.cc:18:17: error: 'f_b' was not declared in this scope
   18 |                 f_b=find(b);
      |                 ^~~
a.cc:24:14: error: 'ans' was not declared in this scope; did you mean 'abs'?
   24 |              ans++ ;
      |              ^~~
      |              abs
a.cc:25:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   25 |         cout<<ans;
      |               ^~~
      |               abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
int n,m;
int p[100005];
int find(int x){
	if(x!=p[x])
	  p[x]=find(p[x]);
	return p[x];
}
int main(){
	cin>>n>>m;
	for(int i;i<=n;i++)
	int a,b,c,f_a,f_b,ans=0;
	while(m--){
		cin>>a>>b>>c;
		f_a=find(a);
		f_b=find(b);
		if(f_a=f_b)
		  p[f_a]=f_b;
	}
	for(int i=1;i<=100005;i++)
	   if(i==p[i])
	     ans++ ;
	cout<<ans;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:22: error: 'a' was not declared in this scope
   15 |                 cin>>a>>b>>c;
      |                      ^
a.cc:15:25: error: 'b' was not declared in this scope
   15 |                 cin>>a>>b>>c;
      |                         ^
a.cc:15:28: error: 'c' was not declared in this scope
   15 |                 cin>>a>>b>>c;
      |                            ^
a.cc:16:17: error: 'f_a' was not declared in this scope; did you mean 'fma'?
   16 |                 f_a=find(a);
      |                 ^~~
      |                 fma
a.cc:17:17: error: 'f_b' was not declared in this scope
   17 |                 f_b=find(b);
      |                 ^~~
a.cc:23:14: error: 'ans' was not declared in this scope; did you mean 'abs'?
   23 |              ans++ ;
      |              ^~~
      |              abs
a.cc:24:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   24 |         cout<<ans;
      |               ^~~
      |               abs
Language: C++

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int par[100010];
int root[100010];
   
void init( int n ){
  for(int i=0;i<n;i++){
    par[i] = i ;
    root[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 ){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  
  if(root[x] < root[y]){
    par[x] = y;
  }
  else{
    par[y] = x ;
    if(root[x] == root[y]) root[x]++;
  }
}

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


int main(){
  
  init(100010);
  
  int n , m;
  
  int a[100010],b[100010],c[100010];
  
  cin >> n >> m;
  
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i] >> c[i];
    
    a[i]--;
    b[i]--:
    c[i]--;
  }
  
  for(int i=0;i<m;i++){
    unite(a[i] , b[i]);
  }
  
    set<int> se;
    
    for (int i = 0; i < n; ++i) se.insert(uf.root(i));
    
  }
  
cout << (int)se.size() << endl;
}

  
  


Compiler output:
a.cc: In function 'int main()':
a.cc:58:11: error: expected ';' before ':' token
   58 |     b[i]--:
      |           ^
      |           ;
a.cc:68:43: error: 'uf' was not declared in this scope
   68 |     for (int i = 0; i < n; ++i) se.insert(uf.root(i));
      |                                           ^~
a.cc: At global scope:
a.cc:72:1: error: 'cout' does not name a type
   72 | cout << (int)se.size() << endl;
      | ^~~~
a.cc:73:1: error: expected declaration before '}' token
   73 | }
      | ^
Language: C++

int par[100010];
int rank[100010];

void init( int n ){
  for(int i=0;i<n;i++){
    par[i] = i ;
    rank[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 ){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  
  if(rank[x] < rank[y]){
    par[x] = y;
  }
  else{
    par[y] = x ;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

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

void solve(){
  
  init(100010);
  
  int n , m;
  
  int a[100010],b[100010],c[100010];
  
  cin >> n >> m;
  
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i] >> c[i];
    
    a[i]--;
    b[i]--:
    c[i]--;
  }
  int ans = 0;
  
  for(int i=0;i<m;i++){
    if(!(same(a[i] , b[i])){
      ans++;
    }
  
  
  
         

Compiler output:
a.cc: In function 'void solve()':
a.cc:46:3: error: 'cin' was not declared in this scope
   46 |   cin >> n >> m;
      |   ^~~
a.cc:52:11: error: expected ';' before ':' token
   52 |     b[i]--:
      |           ^
      |           ;
a.cc:58:28: error: expected ')' before '{' token
   58 |     if(!(same(a[i] , b[i])){
      |       ~                    ^
      |                            )
a.cc:60:6: error: expected statement at end of input
   60 |     }
      |      ^
a.cc:60:6: error: expected '}' at end of input
a.cc:57:23: note: to match this '{'
   57 |   for(int i=0;i<m;i++){
      |                       ^
a.cc:60:6: error: expected '}' at end of input
   60 |     }
      |      ^
a.cc:38:13: note: to match this '{'
   38 | void solve(){
      |             ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int MAX = 100050;
vector<vector<int>> g;
bool visited[MAX];

void dfs(int v) {
    visited[v] = true;
    for (int to : g[v]) {
        if (!visited[to]) {
            dfs(to);
        }
    }
}

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

    int nVertices, nEdges;
    cin >> nVertices >> nEdges;
    g.resize(nVertices + 1);
    for (int i = 0; i < nEdges; ++i) {
        int u, v, _;
        cin >> u >> v >> _;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int cnt = 0;
    for (int v = 1; v <= nVertices; ++v) {
        if (!visited[v]) {
            dfs(v);
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;

Compiler output:
a.cc: In function 'int main()':
a.cc:40:14: error: expected '}' at end of input
   40 |     return 0;
      |              ^
a.cc:18:12: note: to match this '{'
   18 | int main() {
      |            ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
struct UnionFind {
    vector<ll> par;
    
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
    
    ll root(ll x) {
        if (par[x] < 0) 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 (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    ll size(ll x) {
        return -par[root(x)];
    }
};

int main(){
  ll n,m;cin>>n>>m;
  vector<ll> x(m),y(m),z(m);
  rep(i,m) cin>>x[i]>>y[i]>>z[i],x[i]--,y[i]--;
  Unionfind uf(n);
  rep(i,m) uf.merge(x[i],y[i]);
  set<ll> st;
  rep(i,n) st.insert(root(i));
  cout<<st.size()<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:3: error: 'Unionfind' was not declared in this scope; did you mean 'UnionFind'?
   38 |   Unionfind uf(n);
      |   ^~~~~~~~~
      |   UnionFind
a.cc:39:12: error: 'uf' was not declared in this scope
   39 |   rep(i,m) uf.merge(x[i],y[i]);
      |            ^~
a.cc:41:22: error: 'root' was not declared in this scope
   41 |   rep(i,n) st.insert(root(i));
      |                      ^~~~
Language: Java

import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        UnionFind uf = new UnionFind(n);
        
        for(int i=0; i<m; i++){
            int x = Integer.parseInt(sc.next())-1;
            int y = Integer.parseInt(sc.next())-1;
            int z = Integer.parseInt(sc.next());
            uf.unite(x,y);
        }
        
        Set<Integer> s = new HashaSet<>();
        for(int i=0; i<n; i++){
            s.add(uf.find(i));
        }
        
        System.out.println(s.size());
    }
}

class UnionFind{
    int[] par;
    int[] size;
    
    public UnionFind(int n){
        par = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
        }
        size = new int[n];
        Arrays.fill(size, 1);
    }
    
    public int find(int x){
        if(par[x] == x){
            return x;
        }else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    
    public boolean unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return false;
        
        if(size[x]<size[y]){
            int tmp = x;
            x = y;
            y = tmp;
        }
        size[x] += size[y];
        par[y] = x;
        return true;
    }
    
    public boolean same(int x, int y){
        return find(x)==find(y);
    }
    
    public int size(int x){
        return size[find(x)];
    }
}


Compiler output:
Main.java:20: error: cannot find symbol
        Set<Integer> s = new HashaSet<>();
                             ^
  symbol:   class HashaSet
  location: class Main
1 error
Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	if (ci - cn + 16 > cm) {
		int A = getcha() - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
		return A;
	}
	else {
		int A = *ci++ - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
		return A;
	}
}

int P[100001];
int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

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


	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a, b;
		if (ci - cn + 20 > cm) {
			int A = getcha() - '0';
			while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
			a = Find(A);
			A = getcha() - '0';
			while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
			b = Find(A);
			while (getcha() >= '0');
		}
		else {
			int A = *ci++ - '0';
			while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
			a = Find(A);
			A = *ci++ - '0';
			while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
			b = Find(A);
			while (*ci++ >= '0');
		}
		if (a == b) continue;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
	}

	int kotae = 0;
	rep1(i, N) kotae += (P[i] < 0;
	printf("%d", kotae);

	Would you please return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:81:38: error: expected ')' before ';' token
   81 |         rep1(i, N) kotae += (P[i] < 0;
      |                             ~        ^
      |                                      )
Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

int P[100001];
int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

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


	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a, b;
		if (ci - cn + 20 > cm) {
			int A = getcha() - '0';
			while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
			a = Find(A);
			A = getcha() - '0';
			while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
			b = Find(A);
			while (getcha() >= '0');
		}
		else {
			int A = *ci++ - '0';
			while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
			a = Find(A);
			A = *ci++ - '0';
			while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
			b = Find(A);
			while (*ci++ >= '0');
		}
		if (a == b) continue;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
	}

	int kotae = 0;
	rep1(i, N) kotae += P[i] < 0;
	printf("%d", kotae);

	Would you please return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:17: error: 'getint' was not declared in this scope; did you mean 'getpt'?
   40 |         int N = getint(), M = getint();
      |                 ^~~~~~
      |                 getpt
a.cc:42:16: error: 'M' was not declared in this scope
   42 |         rep(i, M) {
      |                ^
a.cc:8:39: note: in definition of macro 'rep'
    8 | #define rep(i, n) for(int i = 0; i < (n); i++)
      |                                       ^
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
 
class UnionFind {
public:
    ll S;
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
        S = n;
    }
 
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	ll allsize() {return S;}
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m; cin >> n >> m;
    UnionFind tree(n);
    rep(i,m) {
        ll u,v,z; cin >> u >> v >> z;
        u--; v--;
        tree.unite(u,v);
    }
    cout << tree.size() << endl;
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:14: error: 'class UnionFind' has no member named 'unite'
   83 |         tree.unite(u,v);
      |              ^~~~~
a.cc:85:22: error: no matching function for call to 'UnionFind::size()'
   85 |     cout << tree.size() << endl;
      |             ~~~~~~~~~^~
a.cc:69:8: note: candidate: 'll UnionFind::size(ll)'
   69 |     ll size(ll x) { // 素集合のサイズ
      |        ^~~~
a.cc:69:8: note:   candidate expects 1 argument, 0 provided
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
 
class UnionFind {
public:
    ll S;
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
        S = n;
    }
 
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	ll allsize() {return S;}
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    UnionFind tree(n);
    rep(i,m) {
        int u,v,z; cin >> u >> v >> z;
        u--; v--;
        tree.unite(u,v);
    }
    cout << tree.allsize() << endl;
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:14: error: 'class UnionFind' has no member named 'unite'
   83 |         tree.unite(u,v);
      |              ^~~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
 
class UnionFind {
public:
    ll S;
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
        S = n;
    }
 
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	ll allsize() {return S;}
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    UnionFind tree(n);
    rep(i,m) {
        int u,v,z; cin >> u >> v >> z;
        u--; v--;
        tree.unite(u,v);
    }
    cout << tree.size() << endl;
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:14: error: 'class UnionFind' has no member named 'unite'
   83 |         tree.unite(u,v);
      |              ^~~~~
a.cc:85:22: error: no matching function for call to 'UnionFind::size()'
   85 |     cout << tree.size() << endl;
      |             ~~~~~~~~~^~
a.cc:69:8: note: candidate: 'll UnionFind::size(ll)'
   69 |     ll size(ll x) { // 素集合のサイズ
      |        ^~~~
a.cc:69:8: note:   candidate expects 1 argument, 0 provided
Language: C++

def r;gets.split.map &:to_i;end
class UnionFind
  def initialize(n, &block)
    @par = Array.new(n,&:itself)
    @rank = Array.new(n,1)
    instance_eval(&block) if block_given?
  end

  def root(a)
    par = @par[a]
    a == par ? a : @par[a] = root(par)
  end

  def unite(a,b)
    a = root(a); b = root(b)
    return if a == b

    @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
    @rank[a] += 1 if @rank[a] == @rank[b]
  end

  def same(a,b)
    root(a) == root(b)
  end

  def roots
    @par.map{|a|root(a)}
  end
end

# sample AB126_E
N,M = r

UnionFind.new(N) do
  M.times do
    a,b = r; a-=1; b-=1;
    unite(a,b)
  end
  UF = roots
end

p UF.uniq.size

Compiler output:
a.cc:4:5: error: stray '@' in program
    4 |     @par = Array.new(n,&:itself)
      |     ^
a.cc:5:5: error: stray '@' in program
    5 |     @rank = Array.new(n,1)
      |     ^
a.cc:10:11: error: stray '@' in program
   10 |     par = @par[a]
      |           ^
a.cc:11:20: error: stray '@' in program
   11 |     a == par ? a : @par[a] = root(par)
      |                    ^
a.cc:18:5: error: stray '@' in program
   18 |     @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
      |     ^
a.cc:18:16: error: stray '@' in program
   18 |     @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
      |                ^
a.cc:18:27: error: stray '@' in program
   18 |     @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
      |                           ^
a.cc:18:41: error: stray '@' in program
   18 |     @rank[a] < @rank[b] ? @par[a] = b : @par[b] = a
      |                                         ^
a.cc:19:5: error: stray '@' in program
   19 |     @rank[a] += 1 if @rank[a] == @rank[b]
      |     ^
a.cc:19:22: error: stray '@' in program
   19 |     @rank[a] += 1 if @rank[a] == @rank[b]
      |                      ^
a.cc:19:34: error: stray '@' in program
   19 |     @rank[a] += 1 if @rank[a] == @rank[b]
      |                                  ^
a.cc:27:5: error: stray '@' in program
   27 |     @par.map{|a|root(a)}
      |     ^
a.cc:31:3: error: invalid preprocessing directive #sample
   31 | # sample AB126_E
      |   ^~~~~~
a.cc:1:1: error: 'def' does not name a type
    1 | def r;gets.split.map &:to_i;end
      | ^~~
a.cc:1:7: error: 'gets' does not name a type
    1 | def r;gets.split.map &:to_i;end
      |       ^~~~
a.cc:1:29: error: 'end' does not name a type
    1 | def r;gets.split.map &:to_i;end
      |                             ^~~
a.cc:15:18: error: 'b' does not name a type
   15 |     a = root(a); b = root(b)
      |                  ^
a.cc:28:3: error: 'end' does not name a type
   28 |   end
      |   ^~~
a.cc:36:14: error: 'a' does not name a type
   36 |     a,b = r; a-=1; b-=1;
      |              ^
a.cc:36:20: error: 'b' does not name a type
   36 |     a,b = r; a-=1; b-=1;
      |                    ^
a.cc:37:10: error: expected constructor, destructor, or type conversion before '(' token
   37 |     unite(a,b)
      |          ^
Language: C++

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N,M;
	scanf("%d%d", &N,&M);
	int Card[N];
	memset(Card, 0, sizeof(Card));
	int X[M],Y[M],Z[M];
	for(int i = 0; i < M; i++) scanf("%d%d%d", X,Y,Z);
	int cnt = N;
	for(int i = 0; i < M; i++)
	{
		if(Card[X[i]] == 0 && Card[Y[i]] == 0)
		{
			cnt -= 1;
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
		else if(Card[X[i]] == 1 || Card[Y[i]] == 1)
		{
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
	}
	cout << cnt << "\n";
}


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

#include <iostream>
using namespace std;
int main()
{
	int N,M;
	scanf("%d%d", &N,&M);
	int Card[N];
	memset(Card, 0, sizeof(Card));
	int X[M],Y[M],Z[M];
	for(int i = 0; i < M; i++) scanf("%d%d%d", X,Y,Z);
	int cnt = N;
	for(int i = 0; i < M; i++)
	{
		if(Card[X[i]] == 0 && Card[Y[i]] == 0)
		{
			cnt -= 1;
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
		else if(Card[X[i]] == 1 || Card[Y[i]] == 1)
		{
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
	}
	cout << cnt << "\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: 'memset' was not declared in this scope
    8 |         memset(Card, 0, sizeof(Card));
      |         ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | using namespace std;
Language: C++

#include <iostream>
using namespace std;



int main()
{
	int N,M;
	scanf("%d%d", &N,&M);
	int Card[N];
	memset(Card, 0, sizeof(Card));
	int X[M],Y[M],Z[M];
	for(int i = 0; i < M; i++) scanf("%d%d%d", X,Y,Z);
	int cnt = N;
	for(int i = 0; i < M; i++)
	{
		if(Card[X[i]] == 0 && Card[Y[i]] == 0)
		{
			cnt -= 1;
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
		else if(Card[X[i]] == 1 || Card[Y[i]] == 1)
		{
			Card[X[i]] = 1;
			Card[Y[i]] = 1;
		}
	}

	cout << cnt << "\n";

}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:9: error: 'memset' was not declared in this scope
   11 |         memset(Card, 0, sizeof(Card));
      |         ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | using namespace std;
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int n,m; cin >> n >> m;
    UnionFind uf(n);
    vector<int> x(m), y(m), z(m);
    rep(i,m){
        cin >> x[i] >> y[i] >> z[i];
        x[i]--; y[i]--;
    }

    rep(i,m) uf.unite(x[i], y[i]);
    set<int> s;
    rep(i,n) s.insert(uf.root(i));
    int ans = s.size();
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:26: error: 'struct UnionFind' has no member named 'root'
   46 |     rep(i,n) s.insert(uf.root(i));
      |                          ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

int N,M;

vector<int> par;
vector<int> rankk;

void init(int n){
    
    for (int i = 0; i < N; i++) {
        par.push_back(i);
        rankk.push_back(0);
    }
    
}

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

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


bool same(int x, int y){
    return find(x) == find(y);
}
    
int main(){
    
    cin >> N >> M;
    init(N);
    
    for (int i = 0; i < M; i++) {
        
        int a,b,c;
        cin >> a >> b >> c;
        unit(a-1, b-1);
    }
    
    
    
    sort(par.begin(), par.end());
    int ans = 1;
    
    for (int i = 0; i < N-1; i++) {
        if (par[i] != par[i+1]) {
            ans += 1;
        }
    }
    
    cout << ans << endl;
    
}

    
}


Compiler output:
a.cc:85:1: error: expected declaration before '}' token
   85 | }
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

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

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

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

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};



typedef tuple<ll, ll, ll> T;


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

    int n, m; cin >> n >> m;
    UnionFind uni(n);
 
    for(int i=0; i<m; i++){
        int x,y,z; cin >> x >> y >> z;
        --x; --y;
        uni.connect(x, y);
    }
 
    map<int, int> mp;
    for(int i=0; i<N; i++) ++mp[uni.root(i)];
    cout << mp.size() << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:106:20: error: 'N' was not declared in this scope
  106 |     for(int i=0; i<N; i++) ++mp[uni.root(i)];
      |                    ^
Language: C++

#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <stack>

using namespace std;

#define maxN 100000
#define maxM 100000

stack<int> parents[maxN];
set<int> all;

int func(int i){
  all.erase(i);

  while( !parents[i].empty() && (all.find(parents[i].top()) == all.end() ) ){
    parents[i].pop();
  }
  while(!parents[i].empty()){
    func(parents[i].top());
    parents[i].pop();
  }
  return 0;
}

int main(){
  int N, M;
  int X, Y, Z;
  int counter[maxN];
  priority_queue<pair<int, int> > que;
  set<int>::iterator ite;

  long long int res=0;

  memset(counter, maxN, 0);

  cin >> N >> M;
  for(int i=0; i<M; i++){
    cin >> X >> Y >> Z;
    counter[X-1]++;
    counter[Y-1]++;
    parents[X-1].push(Y-1);
    parents[Y-1].push(X-1);
  }
  for(int i = 0; i<N; i++){
    all.insert(i);
    que.push(make_pair(counter[i],i));
  }

  while(!all.empty()){
    res++;
    func(que.top().second);
    que.pop();
    while(!all.empty() && all.find(que.top().second) == all.end()){
      que.pop();
    }
  }
  cout << res <<endl;
  return 0;
}


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

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

int num_groups, p[100000], n, m, a, b, c;
int par(int x) { return (p[x]==x)? x:p[x]=par(p[x]); }
bool isSameGroup(int a, int b) { return par(a) == par(b); }
void merge(int a, int b) {
    num_groups -= (!isSameGroup(a, b));
    p[par(a)] = par(b);
}
                   
int main() {
  cin >> n >> m;
  for (int i=0; i<n; i++) p[i] = ;
  num_groups = n;
  for (int i=0; i<m; i++) {
    cin >> a >> b >> c;
    merge(a-1, b-1);
  }
  cout << num_groups;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:34: error: expected primary-expression before ';' token
   14 |   for (int i=0; i<n; i++) p[i] = ;
      |                                  ^
Language: C++

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

int num_groups, p[100000], n, m, a, b, c;
int par(int x) { return (p[x]==x)? x:p[x]=par(p[x]); }
bool isSameGroup(int a, int b) { return par(a) == par(b); }
void merge(int a, int b) {
    num_groups -= (!isSameGroup(a, b);
    p[par(a)] = par(b);
}
                   
int main() {
  cin >> n >> m;
  for (int i=0; i<n; i++) p[i] = 1;
  num_groups = n;
  for (int i=0; i<m; i++) {
    cin >> a >> b >> c;
    merge(a-1, b-1);
  }
  cout << num_groups;
}

Compiler output:
a.cc: In function 'void merge(int, int)':
a.cc:8:38: error: expected ')' before ';' token
    8 |     num_groups -= (!isSameGroup(a, b);
      |                   ~                  ^
      |                                      )