Language: C++

#include<bits/stdc++.h>
using namespace std;
 
struct Unionfind{
  vector<int> d;
  Unionfind(int n): d(n,-1){}
  int root(int x){
    if(d[x]<0) return x;
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    if(d[x]>d[y]) swap(x,y);
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};


int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%d", &a[i]);
		p[i] = i;
	}
	
	for (int i = 0; i < m; i ++ )
	{
		int x, y;
		scanf("%d%d", &x, &y);
		
		int pa = find(x), pb = find(y);
		p[pa] = pb;
	}
	
	int res = 0;
	for (int i = 1; i <= n; i ++ )
	{
		int pa = find(a[i]), pb = find(i);
		if (pa == pb) res ++ ;
	}
	printf("%d\n", res);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:24: error: 'n' was not declared in this scope; did you mean 'yn'?
   27 |         scanf("%d%d", &n, &m);
      |                        ^
      |                        yn
a.cc:27:28: error: 'm' was not declared in this scope; did you mean 'tm'?
   27 |         scanf("%d%d", &n, &m);
      |                            ^
      |                            tm
a.cc:30:30: error: 'a' was not declared in this scope
   30 |                 scanf("%d", &a[i]);
      |                              ^
a.cc:31:17: error: 'p' was not declared in this scope
   31 |                 p[i] = i;
      |                 ^
a.cc:39:30: error: no matching function for call to 'find(int&)'
   39 |                 int pa = find(x), pb = find(y);
      |                          ~~~~^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:40:17: error: 'p' was not declared in this scope; did you mean 'pa'?
   40 |                 p[pa] = pb;
      |                 ^
      |                 pa
a.cc:40:25: error: 'pb' was not declared in this scope; did you mean 'pa'?
   40 |                 p[pa] = pb;
      |                         ^~
      |                         pa
a.cc:46:31: error: 'a' was not declared in this scope; did you mean 'pa'?
   46 |                 int pa = find(a[i]), pb = find(i);
      |                               ^
      |                               pa
a.cc:47:27: error: 'pb' was not declared in this scope; did you mean 'pa'?
   47 |                 if (pa == pb) res ++ ;
      |                           ^~
      |                           pa