Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#define mod 1000000007
#define pb push_back
using namespace std;
int par[100009];
int rank[100009],p[100009];
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,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		par[i]=i;
		rank[i]=0;
	}
	for(int i=0;i<m;i++){
		int var1,var2;
		cin>>var1;
		cin>>var2;
		unite(var1,var2);
	}
	for(int i=1;i<=n;i++){
		if(same(i,p[i])){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void unite(int, int)':
a.cc:24:12: error: reference to 'rank' is ambiguous
   24 |         if(rank[x]<rank[y]){
      |            ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~
a.cc:24:20: error: reference to 'rank' is ambiguous
   24 |         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:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~
a.cc:29:20: error: reference to 'rank' is ambiguous
   29 |                 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:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~
a.cc:29:29: error: reference to 'rank' is ambiguous
   29 |                 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:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~
a.cc:29:37: error: reference to 'rank' is ambiguous
   29 |                 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:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:43:17: error: reference to 'rank' is ambiguous
   43 |                 rank[i]=0;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:5: note:                 'int rank [100009]'
   11 | int rank[100009],p[100009];
      |     ^~~~