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

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

using namespace std;

struct uf {
  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;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }

    uf tree(N);
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if (tree.same(i, P[i]-1)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Compiler output:
a.cc:10:3: error: ISO C++ forbids declaration of 'UnionFind' with no type [-fpermissive]
   10 |   UnionFind(int N) : par(N) {
      |   ^~~~~~~~~
a.cc: In member function 'int uf::UnionFind(int)':
a.cc:10:22: error: only constructors take member initializers
   10 |   UnionFind(int N) : par(N) {
      |                      ^~~
a.cc:12:3: warning: no return statement in function returning non-void [-Wreturn-type]
   12 |   }
      |   ^
a.cc: In function 'int main()':
a.cc:39:14: error: no matching function for call to 'uf::uf(int&)'
   39 |     uf tree(N);
      |              ^
a.cc:8:8: note: candidate: 'uf::uf()'
    8 | struct uf {
      |        ^~
a.cc:8:8: note:   candidate expects 0 arguments, 1 provided
a.cc:8:8: note: candidate: 'uf::uf(const uf&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'int' to 'const uf&'
a.cc:8:8: note: candidate: 'uf::uf(uf&&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'int' to 'uf&&'
Language: C++

int n, m;
int p[101010];
int x[101010], y[101010];
int main() {
  cin >> n >> m;
  init(n + 1);
  for (int i=1;i<=n;i++) {
    cin>>p[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    unite(x[i], y[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (find(p[i]) == find(i))ans++;
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:3: error: 'cin' was not declared in this scope
    5 |   cin >> n >> m;
      |   ^~~
a.cc:6:3: error: 'init' was not declared in this scope; did you mean 'int'?
    6 |   init(n + 1);
      |   ^~~~
      |   int
a.cc:12:5: error: 'unite' was not declared in this scope
   12 |     unite(x[i], y[i]);
      |     ^~~~~
a.cc:16:9: error: 'find' was not declared in this scope
   16 |     if (find(p[i]) == find(i))ans++;
      |         ^~~~
a.cc:18:3: error: 'cout' was not declared in this scope
   18 |   cout << ans << endl;
      |   ^~~~
a.cc:18:18: error: 'endl' was not declared in this scope
   18 |   cout << ans << endl;
      |                  ^~~~
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/union_find.hpp"

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  vi p(n);
  REP(i, n) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(n);
  REP(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }

  map<int, set<int>> mp, num;
  REP(i, n) {
    mp[uf.root(i)].insert(p[i]);
    num[uf.root(i)].insert(i);
  }

  ll cnt = 0;
  for(auto &e1: mp) {
    auto it1 = e1.second.begin();
    auto it2 = num[e1.first].begin();
    while(it1 != e1.second.end() && it2 != num[e1.first].end()) {
      if(*it1 < *it2) {
        it1++;
      } else if(*it1 > *it2) {
        it2++;
      } else {
        cnt++;
        it1++;
        it2++;
      }
    }
  }

  cout << cnt << endl;



}
























Compiler output:
a.cc:2:10: fatal error: ../lib/data_structure/union_find.hpp: No such file or directory
    2 | #include "../lib/data_structure/union_find.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int find_(int x,vector<int> &v){
    if(v[x]<0) return x;
    v[x]=find_(v[x],v);
    return v[x];
}

int same_(int a,int b,vector<int> &v){
    if(find_(a,v)==find_(b,v)) return 1;
    return 0;
}

void union_(int a,int b,vector<int> &v){
    if(same_(a,b,v)) return;
    int a_p=find_(a,v),b_p=find_(b,v);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p]+=v[b_p]; v[b_p]=a_p;
}

void print_v(vector<int> v){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int main() {
    int n,m,ans=0; cin>>n>>m;
    vector<int> p(n,0),v(n,-1);
    rep(i,n){
        cin>>p[i]; p[i]--;
    }
    rep(i,m){
        int x,y; cin>>x>>y;
        union_(x-1,y-1,v);
    }
    rep(i,n) if(same_(i,p[i])) ans++;
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:22: error: too few arguments to function 'int same_(int, int, std::vector<int>&)'
   50 |     rep(i,n) if(same_(i,p[i])) ans++;
      |                 ~~~~~^~~~~~~~
a.cc:23:5: note: declared here
   23 | int same_(int a,int b,vector<int> &v){
      |     ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
const double pi=3.141592653589793;
bool used[100000];
int g[100000][0];
void dfs (ll i,vi &k){
    k.pb(i);used[i]=true;
    for(ll x: g[i]){
        if(!used[x])dfs(x,k);
    }
}
int main(){
    ll n,m,ans=0;cin>>n>>m;
  rep(i,n)used[i]=false;
    vi v(n);
    rep(i,n){
        cin>>v[i];
        v[i]--;
    }
    rep(i,m){
        int a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    rep(i,n){
        if(used[i])continue;
        vi k;
        dfs(i,k);
        vi t;
        for(int x:k)t.pb(v[x]);
        sort(all(t));
        for(int x:k)if(binary_search(all(t),x))ans++;
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:12: error: request for member 'push_back' in 'g[a]', which is of non-class type 'int [0]'
    7 | #define pb push_back
      |            ^~~~~~~~~
a.cc:42:14: note: in expansion of macro 'pb'
   42 |         g[a].pb(b);
      |              ^~
a.cc:7:12: error: request for member 'push_back' in 'g[b]', which is of non-class type 'int [0]'
    7 | #define pb push_back
      |            ^~~~~~~~~
a.cc:43:14: note: in expansion of macro 'pb'
   43 |         g[b].pb(a);
      |              ^~
Language: C++

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

const int MAXN = 1e5 + 21;

int a[MAXN];
int n, m, cnt;
int u, v;
long long ans;
vector<int> adj[MAXN], t[MAXN];
bool vis[MAXN];

void dfs(int root);

int main() {
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	for (int i = 1; i <= m; i++) {
		cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	
	for (int i = 1; i <= n; i++)
		if (!vis[i]) {
			cnt++; 
			dfs(i);
		}
	
	for (int i = 1; i <= n; i++)
		vis[i] = false;
	
	for (int i = 1; i <= cnt; i++) {
		for (auto y: t[i])
			vis[y] = true;

		for (auto y: t[i])
			if (vis[a[y]])
				ans++;
		
		for (auto y: t[i])
			vis[y] = false;
	}
	
	cout << ans << '\n';
	return 0;
}

void dfs(int root) {
	t[cnt].push_back(root);

	vis[root] = true;

	for (auto y: adj[root])
		if (!mark[y])
			dfs(y);
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:58:22: error: 'mark' was not declared in this scope
   58 |                 if (!mark[y])
      |                      ^~~~
Language: C++

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vvi g;
vi v;

void dfs(int u, int k) {
	v[u] = k;
	for (auto z:g[u]) {
    if (v[z]) continue;
    dfs(z, k);
  }
}

int main() {
	int n, m;
	cin >> n >> m;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	g = vvi(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	v = vi(n);
  int k = 1;
	for (int i = 0; i < n; i++) {
		if (v[i]) continue;
		dfs(i, k);
    k++;
	}
	int c = 0;
  for (int i = 0; i < n; i++) c += v[i] == v[a[i]];
	cout << c << endl;
}

Compiler output:
a.cc:3:9: error: 'vector' does not name a type
    3 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:4:9: error: 'vector' does not name a type
    4 | typedef vector<vi> vvi;
      |         ^~~~~~
a.cc:6:1: error: 'vvi' does not name a type
    6 | vvi g;
      | ^~~
a.cc:7:1: error: 'vi' does not name a type; did you mean 'void'?
    7 | vi v;
      | ^~
      | void
a.cc: In function 'void dfs(int, int)':
a.cc:10:9: error: 'v' was not declared in this scope
   10 |         v[u] = k;
      |         ^
a.cc:11:21: error: 'g' was not declared in this scope
   11 |         for (auto z:g[u]) {
      |                     ^
a.cc: In function 'int main()':
a.cc:19:9: error: 'cin' was not declared in this scope
   19 |         cin >> n >> m;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:20:9: error: 'vi' was not declared in this scope
   20 |         vi a(n);
      |         ^~
a.cc:22:24: error: 'a' was not declared in this scope
   22 |                 cin >> a[i];
      |                        ^
a.cc:25:9: error: 'g' was not declared in this scope
   25 |         g = vvi(n);
      |         ^
a.cc:25:13: error: 'vvi' was not declared in this scope
   25 |         g = vvi(n);
      |             ^~~
a.cc:34:9: error: 'v' was not declared in this scope
   34 |         v = vi(n);
      |         ^
a.cc:42:46: error: 'a' was not declared in this scope
   42 |   for (int i = 0; i < n; i++) c += v[i] == v[a[i]];
      |                                              ^
a.cc:43:9: error: 'cout' was not declared in this scope
   43 |         cout << c << endl;
      |         ^~~~
a.cc:43:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:22: error: 'endl' was not declared in this scope
   43 |         cout << c << endl;
      |                      ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
Language: C++

# include <iostream>
# include <vector>

typedef long long ll;
using namespace std;

struct UnionFind {
    vector<int> parent;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int p[n], index[n];
    UnionFind uni(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        index[p[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }
    vector<int> children[n];
    for (auto& pp : p) {
        int r = uni.root(pp);
        children[r].push_back(pp);
    }
    ll ans = 0;
    for (auto& ch : children) {
        if (ch.size() == 0) continue;
        vector<int> in;
        for (auto& c : ch) in.push_back(index[c]);
        for (int i = 0; i < ch.size(); i++) {
            int c = ch[i];
            if (find(in.begin(), in.end(), c) != in.end()) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:21: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
   57 |             if (find(in.begin(), in.end(), c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/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> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:57:21: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   57 |             if (find(in.begin(), in.end(), c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

# include <iostream>
# include <vector>

typedef long long ll;
using namespace std;

struct UnionFind {
    vector<int> parent;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int p[n], index[n];
    UnionFind uni(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        index[p[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }
    vector<int> children[n];
    for (auto& pp : p) {
        int r = uni.root(pp);
        children[r].push_back(pp);
    }
    ll ans = 0;
    for (auto& ch : children) {
        if (ch.size() == 0) continue;
        vector<int> in;
        for (auto& c : ch) in.push_back(index[c]);
        for (int i = 0; i < ch.size(); i++) {
            int c = ch[i];
            if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:21: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
   57 |             if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/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> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:57:21: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   57 |             if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

# include <iostream>
# include <vector>

typedef long long ll;
using namespace std;

struct UnionFind {
    vector<int> parent;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int p[n], index[n];
    UnionFind uni(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        index[p[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }
    vector<int> children[n];
    for (auto& pp : p) {
        int r = uni.root(pp);
        children[r].push_back(pp);
    }
    ll ans = 0;
    for (auto& ch : children) {
        if (ch.size() == 0) continue;
        vector<int> in;
        for (auto& c : ch) in.push_back(index[c]);
        for (auto& c : ch) {
            if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:21: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
   56 |             if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/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> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:56:21: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   56 |             if (find(in.begin(), in.end(), (int)c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

# include <iostream>
# include <vector>

typedef long long ll;
using namespace std;

struct UnionFind {
    vector<int> parent;

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int p[n], index[n];
    UnionFind uni(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        index[p[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        uni.unite(x, y);
    }
    vector<int> children[n];
    for (auto& pp : p) {
        int r = uni.root(pp);
        children[r].push_back(pp);
    }
    ll ans = 0;
    for (auto& ch : children) {
        if (ch.size() == 0) continue;
        vector<int> in;
        for (auto& c : ch) in.push_back(index[c]);
        for (auto& c : ch) {
            if (find(in.begin(), in.end(), c) != in.end()) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:21: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
   56 |             if (find(in.begin(), in.end(), c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/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> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:56:21: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   56 |             if (find(in.begin(), in.end(), c) != in.end()) ans++;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#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 rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

ll a[100001] = {};

//unite x and y : p[uf(x)] = uf(y)
//same x and y : uf(x) == uf(y)
static const ll MAX_N = 100001;
ll p[MAX_N] = {};
ll uf(ll i) {
	if (p[i] == i) return i;
	return p[i] = uf(p[i]);
}
void init_uf() { rep(i, 1, MAX_N)p[i] = i; }

int main() {
	ll n, m; cin >> n >> m;
	repe(i, 1, n) {
		cin >> a[i];
	}
	init_uf();
	rep(i, 0, m) {
		ll x, y; cin >> x >> y;
		if (uf(x) != uf(y))p[uf(x)] = uf(y);
	}
	ll ans = 0;
	repe(i, 1, n)if (uf(i) == uf(a[i]))ans++;
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:19:23: warning: overflow in conversion from 'double' to 'll' {aka 'long long int'} changes value from '1.0000000000000001e+25' to '9223372036854775807' [-Woverflow]
   19 | static const ll INF = 1e25;
      |                       ^~~~
a.cc:27:17: error: redefinition of 'const ll MAX_N'
   27 | static const ll MAX_N = 100001;
      |                 ^~~~~
a.cc:20:17: note: 'const ll MAX_N' previously defined here
   20 | static const ll MAX_N = 100001;
      |                 ^~~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int array[100005]={0};
struct uftree{
private:
  int par[100005]={0},rank[100005]={0};
public:
  uftree(int n){
    for(int i=1;i<=n;i++){
      par[i]=i;
      rank[i]=0;
    }
  }
  int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(rank[a]==rank[b]){
      par[a]=b;
      rank[b]++;
    }
    else if(rank[a]<rank[b]) par[a]=b;
    else par[b]=a;
  }
}
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    array[a]=i;
  }
  uftree uf=uftree(n);
  for(int i=1;i<=m;i++){
    int a,b;
    cin>>a>>b;
    uf.unite(a,b);
  }
  int ans=0;
  for(int i=1;i<=n;i++) if(uf.same(array[i],i)) ans++;
  cout<<ans<<endl;
}


Compiler output:
a.cc:35:2: error: expected ';' after struct definition
   35 | }
      |  ^
      |  ;
a.cc: In function 'int main()':
a.cc:42:5: error: reference to 'array' is ambiguous
   42 |     array[a]=i;
      |     ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:7:5: note:                 'int array [100005]'
    7 | int array[100005]={0};
      |     ^~~~~
a.cc:51:36: error: reference to 'array' is ambiguous
   51 |   for(int i=1;i<=n;i++) if(uf.same(array[i],i)) ans++;
      |                                    ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:7:5: note:                 'int array [100005]'
    7 | int array[100005]={0};
      |     ^~~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int array[100005]={0};
struct uftree{
private:
  int par[100005]={0},rank[100005]={0};
public:
  uftree(int n){
    for(int i=1;i<=n;i++){
      par[i]=i;
      rank[i]=0;
    }
  }
  int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(rank[a]==rank[b]){
      par[a]=b;
      rank[b]++;
    };
    else if(rank[a]<rank[b]) par[a]=b;
    else par[b]=a;
  }
}
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    array[a]=i;
  }
  uftree uf=uftree(n);
  for(int i=1;i<=m;i++){
    int a,b;
    cin>>a>>b;
    uf.unite(a,b);
  }
  int ans=0;
  for(int i=1;i<=n;i++) if(uf.unite(array[i],i)) ans++;
  cout<<ans<<endl;
}


Compiler output:
a.cc:35:2: error: expected ';' after struct definition
   35 | }
      |  ^
      |  ;
a.cc: In member function 'void uftree::unite(int, int)':
a.cc:32:5: error: 'else' without a previous 'if'
   32 |     else if(rank[a]<rank[b]) par[a]=b;
      |     ^~~~
a.cc: In function 'int main()':
a.cc:42:5: error: reference to 'array' is ambiguous
   42 |     array[a]=i;
      |     ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:7:5: note:                 'int array [100005]'
    7 | int array[100005]={0};
      |     ^~~~~
a.cc:51:37: error: reference to 'array' is ambiguous
   51 |   for(int i=1;i<=n;i++) if(uf.unite(array[i],i)) ans++;
      |                                     ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:7:5: note:                 'int array [100005]'
    7 | int array[100005]={0};
      |     ^~~~~
Language: C++

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);
  vector<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-1,y-1);
  }
  int sum=0;
  for(int i=0;i<N;i++)if(tree.same(i+1,p[i]))sum++;
  cout << sum;
}

Compiler output:
a.cc:2:5: error: 'vector' does not name a type
    2 |     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
      |     ^~~~~~
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:4:24: error: class 'UnionFind' does not have any field named 'par'
    4 |     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
      |                        ^~~
a.cc:5:36: error: 'par' was not declared in this scope
    5 |         for(int i = 0; i < N; i++) par[i] = i;
      |                                    ^~~
a.cc: In member function 'int UnionFind::root(int)':
a.cc:9:13: error: 'par' was not declared in this scope
    9 |         if (par[x] == x) return x;
      |             ^~~
a.cc:10:16: error: 'par' was not declared in this scope
   10 |         return par[x] = root(par[x]);
      |                ^~~
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:17:9: error: 'par' was not declared in this scope
   17 |         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
      |         ^~~
a.cc: In function 'int main()':
a.cc:28:3: error: 'cin' was not declared in this scope
   28 |   cin >> N >> M;
      |   ^~~
a.cc:30:3: error: 'vector' was not declared in this scope
   30 |   vector<int> p(N);
      |   ^~~~~~
a.cc:30:10: error: expected primary-expression before 'int'
   30 |   vector<int> p(N);
      |          ^~~
a.cc:31:30: error: 'p' was not declared in this scope
   31 |   for(int i=0;i<N;i++)cin >> p[i];
      |                              ^
a.cc:38:40: error: 'p' was not declared in this scope
   38 |   for(int i=0;i<N;i++)if(tree.same(i+1,p[i]))sum++;
      |                                        ^
a.cc:39:3: error: 'cout' was not declared in this scope
   39 |   cout << sum;
      |   ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define F first
#define S second
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e9;
const int MAX_N = 1e5;
int par[MAX_N];
int ufrank[MAX_N];
int ufsize[MAX_N];
void init(int ufsize_of_tree){
    for (int i = 0; i < ufsize_of_tree; i++)
    {
        par[i] = i;
        ufrank[i] = 0;
        ufsize[i] = 1;
    } 
}
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(ufrank[x] < ufrank[y]){
        par[x] = y;
    int sx = ufsize[x], sy = ufsize[y];
    ufsize[x] = ufsize[y] = sx + sy;
    }else{
        par[y] = x;
        if(ufrank[x] == ufrank[y]) ufrank[x]++;
        int sx = ufsize[x], sy = ufsize[y];
        ufsize[x] = ufsize[y] = sx + sy;
    }
}
bool same(int x,int y){
    return find(x) == find(y);
}
int main(){

    int n,m;cin>>n>>m; init(n);
    vector<int> p(n); rep(n){int x;cin>>x;p[i] = --x;}
    rep(m){
        int a,b;cin>>a>>b; a--,b--;
        unite(a,b);
    }
    //////////////////////////////////
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(same(p[i],i) || i == p[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:40:21: error: extended character 　 is not valid in an identifier
   40 |     if(par[x] == x) return　x;
      |                     ^
a.cc: In function 'int find(int)':
a.cc:40:21: error: 'return\U00003000x' was not declared in this scope
   40 |     if(par[x] == x) return　x;
      |                     ^~~~~~~~~
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define F first
#define S second
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e9;
const int MAX_N = 1e5;
int par[MAX_N];
int ufrank[MAX_N];
int ufsize[MAX_N];
void init(int ufsize_of_tree){
    for (int i = 0; i < ufsize_of_tree; i++)
    {
        par[i] = i;
        ufrank[i] = 0;
        ufsize[i] = 1;
    } 
}
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(ufrank[x] < ufrank[y]){
        par[x] = y;
    int sx = ufsize[x], sy = ufsize[y];
    ufsize[x] = ufsize[y] = sx + sy;
    }else{
        par[y] = x;
        if(ufrank[x] == ufrank[y]) ufrank[x]++;
        int sx = ufsize[x], sy = ufsize[y];
        ufsize[x] = ufsize[y] = sx + sy;
    }
}
bool same(int x,int y){
    return find(x) == find(y);
}
int main(){

    int n,m;cin>>n>>m; init(n);
    vector<int> p(n); rep(n){int x;cin>>x;p[i] = --x;}
    rep(m){
        int a,b;cin>>a>>b; a--,b--;
        unite(a,b);
    }
    //////////////////////////////////
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(same(p[i],i) || i == p[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:40:22: error: extended character 　 is not valid in an identifier
   40 |     if(par[x] == x ) return　x;
      |                      ^
a.cc: In function 'int find(int)':
a.cc:40:22: error: 'return\U00003000x' was not declared in this scope
   40 |     if(par[x] == x ) return　x;
      |                      ^~~~~~~~~
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <Windows.h>
#include <math.h>
//#include "Header.h"

void check(int *q, int *x, int *y, int m, int index);


int main(){
	int n, m;		// 要素数
	scanf_s("%d %d", &n, &m);
	int* p = new int[n];
	int* x = new int[m];
	int* y = new int[m];
	for (int i = 0; i < n; i++)
	{
		scanf_s("%d", &p[i]);
	}
	for (int j = 0; j < m; j++)
	{
		scanf_s("%d %d", &x[j], &y[j]);
	}

	int count = 0;
	for (int i = 0; i < n; i++)
	{
		int* q = new int[n] {0};		// チェック用
		check(q, x, y, m, i + 1);

		for (int ii = 0; ii < n; ii++)
		{
			if (q[ii] == 1 && i + 1 == p[ii])
			{
				count++;
				break;
			}
		}
		delete[] q;
	}

	printf("%d", count);
	//system("pause");
	delete[] p;
	delete[] x;
	delete[] y;
	return 0;
}

// indexとnの時nで再度check
void check(int *q, int *x, int *y, int m, int index)
{
	q[index - 1] = 1;
	for (int j = 0; j < m; j++)
	{
		bool flag = q[x[j] - 1] == 0 || q[y[j] - 1] == 0;
		if (flag && (x[j] == index || y[j] == index))
		{
			int n = (x[j] == index) ? y[j] : x[j];
			q[x[j] - 1] = 1;
			q[y[j] - 1] = 1;
			check(q, x, y, m, n);
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:9: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   13 |         scanf_s("%d %d", &n, &m);
      |         ^~~~~~~
      |         scanf
Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#include <math.h>
#include "Header.h"

void check(int *q, int *x, int *y, int m, int index);


int main(){
	int n, m;		// 要素数
	scanf_s("%d %d", &n, &m);
	int* p = new int[n];
	int* x = new int[m];
	int* y = new int[m];
	for (int i = 0; i < n; i++)
	{
		scanf_s("%d", &p[i]);
	}
	for (int j = 0; j < m; j++)
	{
		scanf_s("%d %d", &x[j], &y[j]);
	}

	int count = 0;
	for (int i = 0; i < n; i++)
	{
		int* q = new int[n] {0};		// チェック用
		check(q, x, y, m, i + 1);

		for (int ii = 0; ii < n; ii++)
		{
			if (q[ii] == 1 && i + 1 == p[ii])
			{
				count++;
				break;
			}
		}
		delete[] q;
	}

	printf("%d", count);
	system("pause");
	delete[] p;
	delete[] x;
	delete[] y;
	return 0;
}

// indexとnの時nで再度check
void check(int *q, int *x, int *y, int m, int index)
{
	q[index - 1] = 1;
	for (int j = 0; j < m; j++)
	{
		bool flag = q[x[j] - 1] == 0 || q[y[j] - 1] == 0;
		if (flag && (x[j] == index || y[j] == index))
		{
			int n = (x[j] == index) ? y[j] : x[j];
			q[x[j] - 1] = 1;
			q[y[j] - 1] = 1;
			check(q, x, y, m, n);
		}
	}
}

Compiler output:
a.cc:4:10: fatal error: Windows.h: No such file or directory
    4 | #include <Windows.h>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<cstdio>
#define N 100001
int n,m,i,c,a[N],p[N];
int f(int j){
	if(p[j]==p)return p;
	return p[j]=f(p[j]);
}
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",a+i),p[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		if(f(x)!=f(y))p[f(x)]=f(y);
	}
	for(i=1;i<=n;i++)if(f(i)==f(a[i]))c++;
	printf("%d",c);
}


Compiler output:
a.cc: In function 'int f(int)':
a.cc:5:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
    5 |         if(p[j]==p)return p;
      |            ~~~~^~~
a.cc:5:27: error: invalid conversion from 'int*' to 'int' [-fpermissive]
    5 |         if(p[j]==p)return p;
      |                           ^
      |                           |
      |                           int*
a.cc: In function 'int main()':
a.cc:12:31: error: 'x' was not declared in this scope
   12 |                 scanf("%d%d",&x,&y);
      |                               ^
a.cc:12:34: error: 'y' was not declared in this scope
   12 |                 scanf("%d%d",&x,&y);
      |                                  ^
Language: C++

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0)return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool unite(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B)
			return false;

		if (size(A) < size(B))
			swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}
};
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	VI P(N);
	VI X(M);
	VI Y(M);
	UnionFind uni(N);
	REP(i, N)cin >> P[i];
	REP(i, M) {
		cin >> X[i] >> Y[i];
		X[i]--;
		Y[i]--;
		uni.unite(X[i], Y[i]);
	}
	int ans = 0;
	eFOR(i,1,N){
		if (root(P[i - 1]) == root(i))ans++;
	}
	cout << ans << endl;
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:84:21: error: 'root' was not declared in this scope
   84 |                 if (root(P[i - 1]) == root(i))ans++;
      |                     ^~~~
Language: C++

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0)return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool unite(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B)
			return false;

		if (size(A) < size(B))
			swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}
};
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	VI P(N);
	VI X(M);
	VI Y(M);
	UnionFind uni(N);
	REP(i, N)cin >> P[i];
	REP(i, M) {
		cin >> X[i] >> Y[i];
		X[i]--;
		Y[i]--;
		uni.unite(X[i], Y[i]);
	}
	int ans = 0;
	eFOR(i,1,N{
		if (root(P[i - 1]) == root(i))ans++;
	}
	cout << ans << endl;
	return 0;
}



Compiler output:
a.cc:89:1: error: unterminated argument list invoking macro "eFOR"
   89 | 
      | ^
a.cc: In function 'int main()':
a.cc:83:9: error: 'eFOR' was not declared in this scope
   83 |         eFOR(i,1,N{
      |         ^~~~
a.cc:83:13: error: expected '}' at end of input
   83 |         eFOR(i,1,N{
      |             ^
a.cc:66:14: note: to match this '{'
   66 | signed main(){
      |              ^
Language: C++

#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

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

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

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

signed main() {
  int n,m;cin>>n>>m;int p[110000];p[0] = INF;repd(i,1,n+1)cin>>p[i];
  int par[110000];rep(i,110000)par[i] = i;int ans = 0;
  rep(i,m){
    int x,y;cin>>x>>y;
    unite(x,y,par);
  }
  vector<int> roots;
  repd(i,1,n+1)if(par[i] == i)roots.push_back(i);
  sort(roots.begin(), roots.end());
  vector<vector<int>> nodes(roots.size()), nums(roots.size());
  repd(i,1,n+1){
    auto itr = lower_bound(roots.begin(), roots.end(), root(i));
    nodes[itr-roots.begin()].push_back(i);
    nums[itr-roots.begin()].push_back(p[i]);
  }
  rep(i,nums.size()){
    sort(nums[i].begin(), nums[i].end());
  }
  rep(i,nodes.size()){
    rep(j,nodes[i].size()){
      ans += (int)binary_search(nums[i].begin(), nums[i].end(), nodes[i][j]);
    }
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:60: error: too few arguments to function 'int root(int, int*)'
   43 |     auto itr = lower_bound(roots.begin(), roots.end(), root(i));
      |                                                        ~~~~^~~
a.cc:12:5: note: declared here
   12 | int root(int x, int par[]){
      |     ^~~~