Language: C++

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int par[100001];
int treesize[100001];
int group = 100000;

int find(int x) {           //親探し
	if (x == par[x]) {
		return x;
	}
	else {
		int z = find(par[x]);
		par[x] = z;
		return z;
	}
}

bool  unit(int x, int y) {

	int xpar = find(x);
	int ypar = find(y);

	if (xpar == ypar) { return false; }   //すでに結合済み
	group--;
	par[ypar] = xpar;
	treesize[xpar] += treesize[ypar];
	return true;
}

int main()
{
	int N,M;
	cin >> N >> M;
	map<int, int> K;
	fx(N) {
		int p;
		cin >> p;
		par[p] = p;
		K[p] = x + 1;
	}
	fx(M) {
		int a, b;
		cin >> a >> b;
		unit(a, b);
	}
	int ans = 0;
	fx(N) {
		if (find(x+1)==find(K[x+1])) {
			ans++;
		}
	}
	ce(ans)
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:44:17: error: a function-definition is not allowed here before '{' token
   44 | int find(int x) {           //親探し
      |                 ^
a.cc:55:26: error: a function-definition is not allowed here before '{' token
   55 | bool  unit(int x, int y) {
      |                          ^
a.cc:67:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   67 | int main()
      |         ^~
a.cc:67:9: note: remove parentheses to default-initialize a variable
   67 | int main()
      |         ^~
      |         --
a.cc:67:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:68:1: error: a function-definition is not allowed here before '{' token
   68 | {
      | ^
a.cc:91:2: error: expected '}' at end of input
   91 | }
      |  ^
a.cc:39:1: note: to match this '{'
   39 | {
      | ^