Language: C++

#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100002
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;

int par[MAX_N];
int rank[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,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 res=0,x[100001],y[100001],N,M,p[100001];
  cin >> N >> M;
  REP(i,N) cin >> p[i];
  REP(i,M) cin >> x[i] >> y[i];
  init(N+1);
  REP(i,M) unite(x[i],y[i]);
  REP(i,N) if(same(i+1,p[i]))res++;
  cout << res << endl;
  return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:23:5: error: reference to 'rank' is ambiguous
   23 |     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/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:41:6: error: reference to 'rank' is ambiguous
   41 |   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:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~
a.cc:41:16: error: reference to 'rank' is ambiguous
   41 |   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:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~
a.cc:45:8: error: reference to 'rank' is ambiguous
   45 |     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:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~
a.cc:45:19: error: reference to 'rank' is ambiguous
   45 |     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:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~
a.cc:45:28: error: reference to 'rank' is ambiguous
   45 |     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:17:5: note:                 'int rank [100002]'
   17 | int rank[MAX_N];
      |     ^~~~