criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	string s;
	int K;

	cin >> s >> K;

	int len = s.length();

	vector<string> tbl;

	int cnt = 0;

	for (size_t i = len; i >= 1; i--)
	{
		for (size_t j = 0; j <= len-i; j++)
		{
			string tmp = s.substr(j, i);

			auto it = tbl.begin();
			for (; it != tbl.end(); it++)
			{
				int res = strcmp(it->c_str(), tmp.c_str());

				if (res == 0)
				{
					goto nostr;
				}
				else if(res == 1)
				{
					break;
				}
			}
			tbl.insert(it, tmp);
			cnt++;
		nostr:;
		}
	}

end:

	cout << tbl[K-1] << endl;


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:43: error: 'strcmp' was not declared in this scope
   28 |                                 int res = strcmp(it->c_str(), tmp.c_str());
      |                                           ^~~~~~
a.cc:4:1: note: 'strcmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <vector>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<string> sub;
    for (int i = 1; i <= 5; ++i) {
        for (int j = 0; j <= s.size() - i; ++j) {
            sub.push_back(s.substr(j, i));
        }
    }
    sort(sub.begin(), sub.end());
    sub.erase(unique(sub.begin(), sub.end()), sub.end());
    cout << sub.at(k - 1) << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |     sort(sub.begin(), sub.end());
      |     ^~~~
      |     short
a.cc:18:15: error: 'unique' was not declared in this scope
   18 |     sub.erase(unique(sub.begin(), sub.end()), sub.end());
      |               ^~~~~~
Language: C++

#include <cstdio>
#include <set>
#include <string>
using namespace std;

int cmp(const void* a, const void* b)
{
	return strcmp((char*)a, (char*)b);
}
int main()
{
	char s[5001];
	int k;
	scanf("%s %d", s, &k);

	int len = strlen(s), idx = 0;
	set<string> lex;
	for (int i = 0; i < len; ++i)
	{
		string tmp;
		for (int j = 0; i + j < len && j < 5; ++j)
		{
			tmp.push_back(s[i + j]);
			lex.insert(tmp);
		}
	}

	auto it = lex.begin();
	for (; --k; ++it);
	puts(it->c_str());

	return 0;
}

Compiler output:
a.cc: In function 'int cmp(const void*, const void*)':
a.cc:8:16: error: 'strcmp' was not declared in this scope
    8 |         return strcmp((char*)a, (char*)b);
      |                ^~~~~~
a.cc:4:1: note: 'strcmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <string>
  +++ |+#include <cstring>
    4 | using namespace std;
a.cc: In function 'int main()':
a.cc:16:19: error: 'strlen' was not declared in this scope
   16 |         int len = strlen(s), idx = 0;
      |                   ^~~~~~
a.cc:16:19: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    int K;
    cin >> s;
    cin >> K;
    vector<string> subs;
    int s_len = s.size();
    for (int i = 0; i < s_len; i++) {
        for (int j = i; j < s_len; j++) {
            string sub = "";
            for (int sub_i = i; sub_i <= j; sub_i++) {
                sub += s[sub_i];
            }
            subs.push_back(sub);
        }
    }
    std::sort(subs.begin(),subs.end());
    subs.erase(std::unique(subs.begin(),subs.end()),subs.end());
    
    cout << subs[K] << "\n";
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:10: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
   24 |     std::sort(subs.begin(),subs.end());
      |          ^~~~
      |          qsort
a.cc:25:21: error: 'unique' is not a member of 'std'
   25 |     subs.erase(std::unique(subs.begin(),subs.end()),subs.end());
      |                     ^~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    int K;
    cin >> s;
    cin >> K;
    vector<string> subs;
    int s_len = s.size();
    for (int i = 0; i < s_len; i++) {
        for (int j = i; j < s_len; j++) {
            string sub = "";
            for (int sub_i = i; sub_i <= j; sub_i++) {
                sub += s[sub_i];
            }
            subs.push_back(sub);
        }
    }
    sort(subs.begin(),subs.end());
    subs.erase(unique(subs.begin(),subs.end()),subs.end());
    
    cout << subs[K] << "\n";
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   24 |     sort(subs.begin(),subs.end());
      |     ^~~~
      |     short
a.cc:25:16: error: 'unique' was not declared in this scope
   25 |     subs.erase(unique(subs.begin(),subs.end()),subs.end());
      |                ^~~~~~
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;

  unordered_set<string> sset;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      string ss = s.substr(i, j + 1);
      sset.insert(ss);
    }
  }

  vector<string> vstr;
  for (auto s : sset) {
    vstr.push_back(s);
    // cout << "+" << s << endl;
  }
  std::sort(vstr.begin(), vstr.end());

  for (auto s : vstr) {
    // cout << "-" << s << endl;
  }
  cout << vstr[K - 1] << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:3: error: 'vector' was not declared in this scope
   21 |   vector<string> vstr;
      |   ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <unordered_set>
  +++ |+#include <vector>
    5 | using namespace std;
a.cc:21:16: error: expected primary-expression before '>' token
   21 |   vector<string> vstr;
      |                ^
a.cc:21:18: error: 'vstr' was not declared in this scope
   21 |   vector<string> vstr;
      |                  ^~~~
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;

  unordered_set<string> sset;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      string ss = s.substr(i, j + 1);
      sset.insert(ss);
    }
  }

  vector<string> vstr;
  for (auto s : sset) {
    vstr.push_back(s);
    cout << "+" << s << endl;
  }
  std::sort(vstr.begin(), vstr.end());

  for (auto s : vstr) {
    cout << "-" << s << endl;
  }
  cout << vstr[K - 1] << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:3: error: 'vector' was not declared in this scope
   21 |   vector<string> vstr;
      |   ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <unordered_set>
  +++ |+#include <vector>
    5 | using namespace std;
a.cc:21:16: error: expected primary-expression before '>' token
   21 |   vector<string> vstr;
      |                ^
a.cc:21:18: error: 'vstr' was not declared in this scope
   21 |   vector<string> vstr;
      |                  ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
  int N,M;cin>>N>>M;
  vector<int>V(N);
  UnionFind UF(N);
  for(int X=0;X<N;X++){
    cin>>V[X];V[X]--;
  }
  for(int X=0;X<M;X++){
    int A,B;cin>>A>>B;A--;B--;
    UF.marge(A,B);
  }
  int H=0;
  for(int X=0;X<N;X++){
    if(UF.issame(X,V[X]))H++;
  }
  cout<<H<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:8: error: 'struct UnionFind' has no member named 'marge'; did you mean 'merge'?
   40 |     UF.marge(A,B);
      |        ^~~~~
      |        merge
Language: C++

/**
*	created: 10.08.2020 15:47:23
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n,-1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        par[x] = root(par[x]);
        return par[x]
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y);
        par[x] += par[y]; par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);}
    int size(int x) {return -par[root(x)];}
};

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    UnionFind uf(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n) if (uf.same(p[i],i+1)) ans++;
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In member function 'long long int UnionFind::root(long long int)':
a.cc:29:5: error: expected ';' before '}' token
   29 |     }
      |     ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
int main(){
ll n,m; cin>>n>>m;
ll a[n]={};
rep(i,n){
cin>>a[i];
}
UnionFind tree(n);
rep(i,m){
int x,y; cin>>x>>y;
tree.unite(x-1,y-1);}
ll ca = 0;
rep(i,n){
if(tree.same(a[i]-1,i) ca++;
   }
cout << ca << endl;}


Compiler output:
a.cc: In function 'int main()':
a.cc:138:23: error: expected ';' before 'ca'
  138 | if(tree.same(a[i]-1,i) ca++;
      |                       ^~~
      |                       ;
a.cc:139:4: error: expected primary-expression before '}' token
  139 |    }
      |    ^
a.cc:138:29: error: expected ')' before '}' token
  138 | if(tree.same(a[i]-1,i) ca++;
      |   ~                         ^
      |                             )
  139 |    }
      |    ~                         
a.cc:139:4: error: expected primary-expression before '}' token
  139 |    }
      |    ^
Language: C++

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

struct UnionFind {
    vector<int> par; // 親の番号
    vector<int> rank;
    // 初期化
    UnionFind(int N) : par(N), rank(N) {
        for(int i = 0; i < N; i++){
            par[i] = i; rank[i] = 0;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
        }else{
            par[y] = x;
            if(rank[x]==rank[b]) rank[x]++;
        }
    }
};
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // x-1の木とy-1の木を併合する
    }

    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if (tree.same(i, P[i]-1)) { //iとP[i]-1が同じ木に属するなら，カウンタに1追加
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Compiler output:
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:30:30: error: 'b' was not declared in this scope
   30 |             if(rank[x]==rank[b]) rank[x]++;
      |                              ^
Language: C++

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

void main(){
    long long N, M;
    cin >> N >> M;
    UnionFind tree(N);
    vector<long long> p(N), x(M), y(M);
    for (long long i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    for (long long i = 0; i < M; i++)
    {
        cin >> x[i] >> y[i];
        tree.unite(x[i], y[i]);
    }
    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        if (tree.same(i+1, p[i]))
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Compiler output:
a.cc:30:1: error: '::main' must return 'int'
   30 | void main(){
      | ^~~~
Language: C++

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

struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }
  
  int root(int x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y) {
    int rx = rppt(x), ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }
  
  bool same(int x, int y) {
    int rx = rppt(x), ry = root(y);
    return rx == ry;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> p(N);
  for(int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  UnionFind tree(N);
  for(int i = 0; i < M; i++) {
    int x, y; cin >> x >> y; x--; y--;
    tree.unite(x, y);
  }
  int count = 0;
  for(int i = 0; i < N; i++) {
    if(tree.same(i, p.at(i))) count++;
  }
  cout << count << endl;
}

Compiler output:
a.cc:25:2: error: expected ';' after struct definition
   25 | }
      |  ^
      |  ;
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:16:14: error: 'rppt' was not declared in this scope
   16 |     int rx = rppt(x), ry = root(y);
      |              ^~~~
a.cc:17:14: error: 'ry' was not declared in this scope; did you mean 'rx'?
   17 |     if(rx == ry) return;
      |              ^~
      |              rx
a.cc:18:15: error: 'ry' was not declared in this scope; did you mean 'rx'?
   18 |     par[rx] = ry;
      |               ^~
      |               rx
a.cc: In member function 'bool UnionFind::same(int, int)':
a.cc:22:14: error: 'rppt' was not declared in this scope
   22 |     int rx = rppt(x), ry = root(y);
      |              ^~~~
a.cc:23:18: error: 'ry' was not declared in this scope; did you mean 'rx'?
   23 |     return rx == ry;
      |                  ^~
      |                  rx
Language: C++

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

template<typename T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<typename T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

bool comp(vll a,vll b){
    return a[1]<b[1];
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    cin>>N>>M;
    vll p(N);
    for(ll i=0;i<N;i++){
        cin>>p[i];
        p[i]--;
    }
    vvll next(N);
    for(ll i=0;i<M;i++){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        next[x].push_back(y);
        next[y].push_back(x);
    }
    
    vll num(N);
    for(ll i=1;;i++){
        bool finish=true;
        ll index=-1;
        for(ll j=0;j<N;j++){
            if(num[j]==0){
                index=j;
                finish=false;
                break;
            }
        }
        if(finish)break;
        stack<ll> open;
        open.push(index);
        num[index]=i;
        while(open.size()>0){
            ll node=open.top();
            open.pop();
            for(ll j=0;j<next[node].size();j++){
                if(num[next[node][j]]==0){
                    num[next[node][j]]=i;
                    open.push(next[node][j]);
                }
            }
        }
    }
    
    vvll num2(N,vll(2));
    for(ll i=0;i<N;i++){
        num2[i][0]=num[i];
        num2[i][1]=p[i];
    }
    
    sort(num2.begin(),num2.end(),comp);
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(num[i]==num2[i][0])ans++;
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:9: error: 'stack' was not declared in this scope
   74 |         stack<ll> open;
      |         ^~~~~
a.cc:10:1: note: 'std::stack' is defined in header '<stack>'; this is probably fixable by adding '#include <stack>'
    9 | #include <set>
  +++ |+#include <stack>
   10 | 
a.cc:74:17: error: expected primary-expression before '>' token
   74 |         stack<ll> open;
      |                 ^
a.cc:74:19: error: 'open' was not declared in this scope; did you mean 'popen'?
   74 |         stack<ll> open;
      |                   ^~~~
      |                   popen
Language: C++

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

struct UnionFind{
  /*データメンバ*/
  vector<int> par; //par[i]:iの親の番号。
  /*コンストラクタ。独自の初期化処理などを行いたいときにコンストラクタを使う。引数の数を変えることで複数のコンストラクタを定義可能。*/
  UnionFind(int N) : par(N) {/*:の後ろに記述されたデータメンバの初期化を行う。*/
    rep(i,N)par[i]=i;
  }

  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){//unite trees
    int rx = root(x);
    int ry = root(y);
    if(rx = ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){
  int N,M; cin>>N>>M
  UnionFind U(N);
  vector<int> P(N);
  rep(i,N)cin>>P.at(i);
  rep(i,M){
    int x,y; cin>>x>>y;
    U.unite(x,y);
  }
  int res = 0;
  rep(i,N){
    if(U.same(i,P.at(i)))res++;
  }
  cout<<res<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:21: error: expected ';' before 'UnionFind'
   38 |   int N,M; cin>>N>>M
      |                     ^
      |                     ;
   39 |   UnionFind U(N);
      |   ~~~~~~~~~          
a.cc:44:5: error: 'U' was not declared in this scope
   44 |     U.unite(x,y);
      |     ^
a.cc:48:8: error: 'U' was not declared in this scope
   48 |     if(U.same(i,P.at(i)))res++;
      |        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        REP(i,n) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par(x));
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
}


int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    UnionFind uf(n);
    REP(i,n) {
        cin >> v[i];
        v[i]--;
    }
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }

    int ans = 0;
    REP(i,n) {
        if (uf.same(i,v[i])) ans++;
    }

    cout << ans << '\n';

    return 0;
}

Compiler output:
a.cc:38:2: error: expected ';' after struct definition
   38 | }
      |  ^
      |  ;
a.cc: In member function 'int UnionFind::root(int)':
a.cc:25:33: error: no match for call to '(std::vector<int>) (int&)'
   25 |         return par[x] = root(par(x));
      |                              ~~~^~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

struct UnionFind {
  vector<int> par;
  
  UnionFind(int N) : par(N) {
    for (int i=0; i<N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }
}

int N, M;
int P[100010];

int main() {
  cin >> N >> M;
  rep(i, 0, N) cin >> P[i];

  UnionFind tree(N);
  rep(i, 0, M) {
    int x, y;
    cin >> x >> y;
    tree.unite(x, y);
  }

  int res = 0;
  rep(i, 0, N) {
    if tree.same(i, P[i]) res++;
  }
  cout << res << endl;
  return 0;
}


Compiler output:
a.cc:57:2: error: expected ';' after struct definition
   57 | }
      |  ^
      |  ;
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:52:3: error: expected ';' before '}' token
   52 |   }
      |   ^
a.cc: In function 'int main()':
a.cc:75:8: error: expected '(' before 'tree'
   75 |     if tree.same(i, P[i]) res++;
      |        ^~~~
      |        (
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

struct UnionFind {
    vector<int> parent;
    UnionFind (int n) : parent(n) {
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int root (int x) {
        if (parent[x] == x) return x;
        return root(parent[x]);
    }

    void unite (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
    }

    bool same_root(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }

    UnionFind tree(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        tree.unite(x, y);
    }

    for (int i = 0; i < n; i++)
    {
        if(tree.same_root(i, p[i])) ans++;
    }
    cout << ans << endl;
    
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:37: error: 'ans' was not declared in this scope; did you mean 'abs'?
   53 |         if(tree.same_root(i, p[i])) ans++;
      |                                     ^~~
      |                                     abs
a.cc:55:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |     cout << ans << endl;
      |             ^~~
      |             abs
Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int N, Q;
vector<pair<int, int>> node;
vector<int> P, X;
vector<pair<int, int>> nodelist;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	cin >> N >> Q;

	for (int i = 0; i < N -1; i++) {
		int temp1, temp2;
		cin >> temp1 >> temp2;
		node.emplace_back(temp1, temp2);
	}

	for (int i = 0; i < Q; i++) {
		int temp;
		cin >> temp;
		P.emplace_back(temp);

		cin >> temp;
		X.emplace_back(temp);
	}

	for (int i = 0; i < N -1; i++) {
		nodelist.emplace_back(node[i].second,i);
		nodelist.emplace_back(node[i].first,i);	
	}
	
	sort(node.begin(), node.end());
	sort(nodelist.begin(), nodelist.end());

	//for (int i = 0; i < 2 * (N - 1); i++) {
	//	cout << nodelist[i].first << ":" << nodelist[i].second << endl;
	//}

	//for (int i = 0; i < N -1; i++) {
	//	cout << node[i].first << ":" << node[i].second << endl;
	//}

	vector<pair<int, int>> tree;

	//子をたどって累積和ー＞ans更新
	for (int i = 0; i < N - 1; i++) {
		tree.emplace_back(bisearch(i), i);
	
	}




}

// 子の格納場所を二分探索で探す
int bisearch(int oya) {
	int start = 0;
	int end = N * 2 - 1;
	int checker = (start + end) / 2;

	int target = nodelist[oya].first;

	while (nodelist[checker].first != target && checker !=oya) {
		if (nodelist[checker].first < target) {
			start = target + 1;
			target = (start + end) / 2;
		}
		else {
			end = target - 1;
			target = (start + end) / 2;
		}
	
	}

	return nodelist[checker].second;



}

Compiler output:
a.cc: In function 'int main()':
a.cc:80:35: error: 'bisearch' was not declared in this scope; did you mean 'bsearch'?
   80 |                 tree.emplace_back(bisearch(i), i);
      |                                   ^~~~~~~~
      |                                   bsearch
Language: C++

#include <iostream>
#include <vector>
using namespace std;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) { 
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return;
        par[rx] = ry;
    }
	
	bool same(int x,int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){
	int n,m;
	cin >> n >> m;
	UnionFind tree(n);
	int p[n];
	for(int i = 0;i<n;i++)cin >> p[i];
	for(int i = 0;i<m;i++){
		int x,y;
		cin >> x >> y;
		tree.unite(x,y);
	}
	int count = 0;
	for(int i = 0;i<n;i++){
		if(same(i,p[i])){
			count++;
		}
	}
	cout << count << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:44:20: error: 'same' was not declared in this scope
   44 |                 if(same(i,p[i])){
      |                    ^~~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) { 
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return;
        par[rx] = ry;
    }
	
	bool same(int x,int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){
	int n,m;
	cin >> n >> m;
	UnionFind tree(n);
	int p[n];
	for(int i = 0;i<n;i++)cin >> p[i];
	for(int i = 0;i<m;i++){
		int x,y;
		cin >> x >> y;
		tree.unite(x,y);
	}
	int count = 0;
	for(int i = 0;i<n;i++){
		if(same(i,p[i]){
			count++;
		}
	}
	cout << count << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:44:20: error: 'same' was not declared in this scope
   44 |                 if(same(i,p[i]){
      |                    ^~~~
a.cc:44:32: error: expected ')' before '{' token
   44 |                 if(same(i,p[i]){
      |                   ~            ^
      |                                )
a.cc:47:9: error: expected primary-expression before '}' token
   47 |         }
      |         ^
Language: C++

#include <iostream>
using namespace std;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) { 
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return;
        par[rx] = ry;
    }
	
	bool same(int x,int y){
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main(){
	int n,m;
	cin >> n >> m;
	UnionFind tree(n);
	int p[n];
	for(int i = 0;i<n;i++)cin >> p[i];
	for(int i = 0;i<m;i++){
		int x,y;
		cin >> x >> y;
		tree.unite(x,y);
	}
	int count = 0;
	for(int i = 0;i<n;i++){
		if(same(i,p[i]){
			count++;
		}
	}
	cout << count << endl;
}

Compiler output:
a.cc:5:5: error: 'vector' does not name a type
    5 |     vector<int> par;
      |     ^~~~~~
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:7:24: error: class 'UnionFind' does not have any field named 'par'
    7 |     UnionFind(int n) : par(n) {
      |                        ^~~
a.cc:8:36: error: 'par' was not declared in this scope
    8 |         for(int i = 0; i < n; i++) par[i] = i;
      |                                    ^~~
a.cc: In member function 'int UnionFind::root(int)':
a.cc:12:13: error: 'par' was not declared in this scope
   12 |         if (par[x] == x) return x;
      |             ^~~
a.cc:13:16: error: 'par' was not declared in this scope
   13 |         return par[x] = root(par[x]);
      |                ^~~
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:20:9: error: 'par' was not declared in this scope
   20 |         par[rx] = ry;
      |         ^~~
a.cc: In function 'int main()':
a.cc:43:20: error: 'same' was not declared in this scope
   43 |                 if(same(i,p[i]){
      |                    ^~~~
a.cc:43:32: error: expected ')' before '{' token
   43 |                 if(same(i,p[i]){
      |                   ~            ^
      |                                )
a.cc:46:9: error: expected primary-expression before '}' token
   46 |         }
      |         ^
Language: C++

class UFT < Array
  def root x
    if self[x] == x
      x
    else
      self[x] = root(self[x])
    end
  end

  def same(x, y)
    return root(x) == root(y)
  end

  def unite(x, y)
    rootx = root(x)
    rooty = root(y)

    if (rootx == rooty)
      return
    else
      self[rootx] = rooty
    end
  end
end

N, M = gets.split.map(&:to_i)
uft = UFT.new(N.times.map(&:itself))
p = gets.split.map(&:to_i)

M.times do
  x, y = gets.split.map(&:to_i)
  uft.unite(x-1, y-1)
end
p uft

cnt = 0
p.each.with_index do |d, i|
  cnt += 1 if uft.same(i, d-1)
end

puts cnt


Compiler output:
a.cc:1:7: error: 'UFT' is not a class template
    1 | class UFT < Array
      |       ^~~
a.cc:1:13: error: 'Array' was not declared in this scope
    1 | class UFT < Array
      |             ^~~~~
a.cc:41:9: error: expected unqualified-id at end of input
   41 | puts cnt
      |         ^
Language: C++

#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n,m;
	cin >> n>> m;
    UnionFind tree(n);
    int p[n];
    fr(i,n){
      cin >> p[i];
    }
    int x,y;
    fr(i,m){
      cin >> x>>y;
      tree.unite(x,y)
    }
    int ans=0;
    fr(i,n){
      if(tree.same(i,p[i])==true)ans++;
    }
      cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:22: error: expected ';' before '}' token
   51 |       tree.unite(x,y)
      |                      ^
      |                      ;
   52 |     }
      |     ~
Language: C++

#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (x % y == 0) return y;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x * y / GCD(x, y);}
//cout << fixed << setprecision(10);

int main(){
  ll n,m; cin>>n>>m;
  vector<ll>p(n);
  rep(i,n) cin>>p[i];
  vector<ll>tr(n);
  rep(i,n) tr[i]=i+1;
  
  ll root(ll x){
  if(tr[x-1]==x) return x;
    return tr[x-1]=root(tr[x-1]);
  }
  
  void unite(ll x,ll y){
  ll rx=root(x), ry=root(y);
    if(rx==ry) return;
    tr[rx-1]=ry;
  }
  
  bool same(ll x,ll y){
  return root(x-1)==root(y-1);
  }
  
  rep(i,m){
  ll x,y; cin>>x>>y;
    unite(x,y);
  }
  ll ans=0;
  for(ll i=1;i<=n;i++){
  if(same(i,v[i-1])) ans++;
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:16: error: a function-definition is not allowed here before '{' token
   19 |   ll root(ll x){
      |                ^
a.cc:24:24: error: a function-definition is not allowed here before '{' token
   24 |   void unite(ll x,ll y){
      |                        ^
a.cc:30:23: error: a function-definition is not allowed here before '{' token
   30 |   bool same(ll x,ll y){
      |                       ^
a.cc:36:5: error: 'unite' was not declared in this scope
   36 |     unite(x,y);
      |     ^~~~~
a.cc:40:13: error: 'v' was not declared in this scope
   40 |   if(same(i,v[i-1])) ans++;
      |             ^
a.cc:40:6: error: 'same' was not declared in this scope
   40 |   if(same(i,v[i-1])) ans++;
      |      ^~~~
Language: C++

    rep(i,m)cin >> xy[i][0] >> xy[i][1];
    rep(i,n+1)parent[i]=i;
    rep(i,m){
        unite(xy[i][0],xy[i][1]);
    } 
    ll res=0;
    DEBUG{
        rep(i,n){
            printf("p%d : %lld\n", i+1, parent[i+1]);
        }
    }
    rep(i,n){
        if(root(i+1)==root(p[i]))res++;
    }
    cout << res << endl;
    return 0;
}


Compiler output:
a.cc:1:8: error: expected constructor, destructor, or type conversion before '(' token
    1 |     rep(i,m)cin >> xy[i][0] >> xy[i][1];
      |        ^
a.cc:2:8: error: expected constructor, destructor, or type conversion before '(' token
    2 |     rep(i,n+1)parent[i]=i;
      |        ^
a.cc:3:8: error: expected constructor, destructor, or type conversion before '(' token
    3 |     rep(i,m){
      |        ^
a.cc:6:5: error: 'll' does not name a type
    6 |     ll res=0;
      |     ^~
a.cc:7:5: error: 'DEBUG' does not name a type
    7 |     DEBUG{
      |     ^~~~~
a.cc:12:8: error: expected constructor, destructor, or type conversion before '(' token
   12 |     rep(i,n){
      |        ^
a.cc:15:5: error: 'cout' does not name a type
   15 |     cout << res << endl;
      |     ^~~~
a.cc:16:5: error: expected unqualified-id before 'return'
   16 |     return 0;
      |     ^~~~~~
a.cc:17:1: error: expected declaration before '}' token
   17 | }
      | ^
Language: C++

#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int n, m;
vector<int>plist;

struct MyStruct
{
	vector<int>list;

	MyStruct(int n) {
		for (int i = 0; i < n; i++) {
			//int num = 0;
			list.push_back(i);
		}
	}

	int root(int r) {
		if (list[r] == r) 	return r;
		root(list[r]);
		//return list[r] = root(list[r]);
	}

	bool same(int x, int y) {
	/*	int xx = root(list[x]);
		int yy = root(list[y]);*/
		int xx = root(x);
		int yy = root(y);
		if (xx == yy)return true;
		return false;
	}

	bool one(int x, int y) {
//		int xx = root(list[x]);
	//	int yy = root(list[y]);
		int xx = root(x);
		int yy = root(y);
		if (xx == yy)return true;
		list[xx] = list[yy];
	}


};

int main() {
	
	cin >> n >> m;

	MyStruct st(n);


	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		plist.push_back(num - 1);
	}

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;

		st.one(x, y);
	}

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		if (st.same(plist[i], i)) {
			cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}


Compiler output:
a.cc:1:10: fatal error: pch.h: No such file or directory
    1 | #include "pch.h"
      |          ^~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


class UnionFind {
public:
	UnionFind(size_t size) : v(size, -1) {}
	vector<int> v;

	int root(int x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(int x) {
		return x == root(x);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (v[x] > v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}

	int size(int x) {
		return -v[root(x)];
	}
};


ll N, M;
vector<ll> p,X,Y;

void input() {
	scanf("%lld%lld", &N, &M);
        a.assign(N,0);
        rep(i,N)cin>>a[i];
	X=vector<ll>(M,0);
	Y=vector<ll>(M,0);
	rep(i,M){
		cin >>X[i]>>Y[i];
		X[i]--;Y[i]--;
	}
}

void solve() {
	UnionFind tree=UnionFind(N);
	ll ans = 0;

	rep(i,M){
		tree.unite(X[i],Y[i]);
	}

	rep(i,N){
		if(tree.same(i,a[i]))ans++;
	}


	p(ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Compiler output:
a.cc:2:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
    2 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


class UnionFind {
public:
	UnionFind(size_t size) : v(size, -1) {}
	vector<int> v;

	int root(int x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(int x) {
		return x == root(x);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (v[x] > v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}

	int size(int x) {
		return -v[root(x)];
	}
};


ll N, M;
vector<ll> p,X,Y;

void input() {
	scanf("%lld%lld", &N, &M);
        a.assign(N,0);
        rep(i,N)cin>>a[i];
	X=vector<ll>(M,0);
	Y=vector<ll>(M,0);
	rep(i,M){
		cin >>X[i]>>Y[i];
		X[i]--;Y[i]--;
	}
}

void solve() {
	UnionFind tree=UnionFind(N);
	ll ans = 0;

	rep(i,M){
		tree.unite(X[i],Y[i]);
	}

	rep(i,N){
		if(tree.same(i,a[i])ans++;
	}


	p(ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Compiler output:
a.cc:2:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
    2 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.