Language: C++

#include <bits/stdc++.h>
using namespace std;
int N, M, parent[10010], rank[10010], pn[10010];
int x, y, one, two;
int ufind(int a)
{    if (parent[a] == a) return a;
    return ufind(parent[a]);	}
void uSet(int a, int b)
{	int x,y;
    x=ufind(a);
    y=ufind(b);
    if (x==y) return;
    if (rank[x]>rank[y])         parent[y] = x;
    else if (rank[x]==rank[y]) {
        parent[y]=x;
        rank[x]++;
    }
    else parent[x]=y;	}
int main()
{
    scanf("%d %d", &N, &M);
    for(int i=1;i<=N;i++) scanf("%d", &pn[i]);
    for(int i=0; i<=N; i++) { parent[i] = i; rank[i] = 1; }
    for(int i=0; i<M; i++) {
        scanf("%d %d", &one, &two);
		uSet(one, two);
    }
    int ans=0;
    for(int i=1;i<=N;i++){
    	if(ufind(pn[i])==ufind(i)) ans++;
	}
	printf("%d",ans);
    return 0;
}


Compiler output:
a.cc: In function 'void uSet(int, int)':
a.cc:13:9: error: reference to 'rank' is ambiguous
   13 |     if (rank[x]>rank[y])         parent[y] = x;
      |         ^~~~
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:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~
a.cc:13:17: error: reference to 'rank' is ambiguous
   13 |     if (rank[x]>rank[y])         parent[y] = x;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~
a.cc:14:14: error: reference to 'rank' is ambiguous
   14 |     else 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:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~
a.cc:14:23: error: reference to 'rank' is ambiguous
   14 |     else 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:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~
a.cc:16:9: error: reference to 'rank' is ambiguous
   16 |         rank[x]++;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~
a.cc: In function 'int main()':
a.cc:23:46: error: reference to 'rank' is ambiguous
   23 |     for(int i=0; i<=N; i++) { parent[i] = i; rank[i] = 1; }
      |                                              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:3:26: note:                 'int rank [10010]'
    3 | int N, M, parent[10010], rank[10010], pn[10010];
      |                          ^~~~