Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define Nodes 100100
#define S second
#define ll long long
using namespace std;
//union find{
#define MAX_N 100100
int par[MAX_N]; // 親
int rank[MAX_N]; // 木の深さ
// 初期化
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]);
}
// xとyの属する集合を併合
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]++;
  }
}
// xとyが同じ集合ならtrue
bool same(int x,int y){
  return find(x) == find(y);
}
int main(){
  int n,m;cin>>n>>m;
  vector<int>num(n);
  init(100010);
  for(int i=0;i<n;i++)cin>>num[i];
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    unite(a,b);
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    if(find(num[i])==find(i+1))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:21:5: error: reference to 'rank' is ambiguous
   21 |     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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:38:6: error: reference to 'rank' is ambiguous
   38 |   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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~
a.cc:38:16: error: reference to 'rank' is ambiguous
   38 |   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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~
a.cc:42:8: error: reference to 'rank' is ambiguous
   42 |     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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~
a.cc:42:19: error: reference to 'rank' is ambiguous
   42 |     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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~
a.cc:42:28: error: reference to 'rank' is ambiguous
   42 |     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:16:5: note:                 'int rank [100100]'
   16 | int rank[MAX_N]; // 木の深さ
      |     ^~~~