Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(int i=m;i<n;i++)

int par[100000];
int rank[100000];

void init(int n){
  rep(i,0,n){
    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);
}

int main() {
  int n,m;
  cin>>n>>m;
  init(n);
  rep(j,0,m){
    int a,b,c;
    cin>>a>>b>>c;
    unite(a-1,b-1);
  }
  
  int a[n];
  rep(i,0,n) a[i]=find(i);
    
  sort(a,a+n);
  int cur=-1;
  int ans=0;
  rep(i,0,n){
    if(cur!=a[i]){
      ans++;
      cur=a[i];
    }
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:12:5: error: reference to 'rank' is ambiguous
   12 |     rank[i]=0;
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:29:6: error: reference to 'rank' is ambiguous
   29 |   if(rank[x]<rank[y]){
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~
a.cc:29:14: error: reference to 'rank' is ambiguous
   29 |   if(rank[x]<rank[y]){
      |              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~
a.cc:34:8: error: reference to 'rank' is ambiguous
   34 |     if(rank[x]==rank[y]) rank[x]++;
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~
a.cc:34:17: error: reference to 'rank' is ambiguous
   34 |     if(rank[x]==rank[y]) rank[x]++;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~
a.cc:34:26: error: reference to 'rank' is ambiguous
   34 |     if(rank[x]==rank[y]) rank[x]++;
      |                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:7:5: note:                 'int rank [100000]'
    7 | int rank[100000];
      |     ^~~~