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

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int graph[100005][100005]; 
bool visit[100005];

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 0; i < len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}

int main(){
        int N,M;
        int p[100005], x[100005], y[100005];
        int ans = 0;
        cin >> N >> M;
        for(int i = 0; i < N; i++) cin >> p[i];
        for(int i = 0; i < M; i++){
                cin >> x[i] >> y[i];
                x[i]--;
                y[i]--;
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 0; i < N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i]-1]) ans++;
        }

        cout << ans << endl;
        return 0;
}




Compiler output:
/tmp/cccwUH2E.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccwUH2E.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccwUH2E.o
/tmp/cccwUH2E.o: in function `main':
a.cc:(.text+0x24f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccwUH2E.o
a.cc:(.text+0x27e): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccwUH2E.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int graph[100005][100005]; 
bool visit[100005];

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 0; i < len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}

int main(){
        int N,M;
        int p[100005], x[100005], y[100005];
        int ans = 0;
        cin >> N >> M;
        for(int i = 0; i < N; i++) cin >> p[i];
        for(int i = 0; i < M; i++){
                cin >> x[i] >> y[i];
                x[i]--;
                y[i]--;
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 0; i < N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i]-1]) ans++;
        }

        cout << ans << endl;
        return 0;
}




Compiler output:
/tmp/cc9bkJ8W.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc9bkJ8W.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc9bkJ8W.o
/tmp/cc9bkJ8W.o: in function `main':
a.cc:(.text+0x24f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc9bkJ8W.o
a.cc:(.text+0x27e): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc9bkJ8W.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int graph[100005][100005]; 
bool visit[100005];

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}

int main(){
        int N,M;
        int p[100005], x[100005], y[100005];
        int ans = 0;
        cin >> N >> M;
        for(int i = 0; i < N; i++) cin >> p[i];
        for(int i = 0; i < M; i++){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}




Compiler output:
/tmp/ccc3AQ2z.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccc3AQ2z.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccc3AQ2z.o
/tmp/ccc3AQ2z.o: in function `main':
a.cc:(.text+0x219): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccc3AQ2z.o
a.cc:(.text+0x248): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccc3AQ2z.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int graph[100005][100005]; 
bool visit[100005];

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}

int main(){
        int N,M;
        int p[100005], x[100005], y[100005];
        int ans = 0;
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}




Compiler output:
/tmp/ccxVyNoW.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccxVyNoW.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccxVyNoW.o
/tmp/ccxVyNoW.o: in function `main':
a.cc:(.text+0x216): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccxVyNoW.o
a.cc:(.text+0x245): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccxVyNoW.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp, int len);

int main(){
        int N,M;
        int p[100005], x[100005], y[100005];
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}



Compiler output:
/tmp/ccUcgqoq.o: in function `main':
a.cc:(.text+0x181): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccUcgqoq.o
a.cc:(.text+0x1b0): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccUcgqoq.o
a.cc:(.text+0x1be): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccUcgqoq.o
a.cc:(.text+0x1c7): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccUcgqoq.o
a.cc:(.text+0x1d9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccUcgqoq.o
/tmp/ccUcgqoq.o: in function `check(int, int)':
a.cc:(.text+0x21d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccUcgqoq.o
a.cc:(.text+0x236): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccUcgqoq.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int N,M;
int p[100005], x[100005], y[100005];
int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp, int len);

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}



Compiler output:
/tmp/cccD1yl3.o: in function `main':
a.cc:(.text+0x1c2): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccD1yl3.o
a.cc:(.text+0x1ff): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccD1yl3.o
a.cc:(.text+0x20d): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cccD1yl3.o
a.cc:(.text+0x216): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cccD1yl3.o
a.cc:(.text+0x22b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cccD1yl3.o
/tmp/cccD1yl3.o: in function `check(int, int)':
a.cc:(.text+0x26f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccD1yl3.o
a.cc:(.text+0x288): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cccD1yl3.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int N,M;
int p[100005], x[100005], y[100005];
int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!(graph[tmp][i])) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccJ9Gal8.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccJ9Gal8.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccJ9Gal8.o
/tmp/ccJ9Gal8.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccJ9Gal8.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccJ9Gal8.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccJ9Gal8.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccJ9Gal8.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccJ9Gal8.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int N,M;
int p[100005], x[100005], y[100005];
int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccpgQrKe.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpgQrKe.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpgQrKe.o
/tmp/ccpgQrKe.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpgQrKe.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccpgQrKe.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccpgQrKe.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccpgQrKe.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccpgQrKe.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int N,M;
int p[100005], x[100005], y[100005];
int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccT30mEn.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccT30mEn.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccT30mEn.o
/tmp/ccT30mEn.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccT30mEn.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccT30mEn.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccT30mEn.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccT30mEn.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccT30mEn.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int N,M;
int p[100005], x[100005], y[100005];
int graph[100005][100005]; 
bool visit[100005];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccjIThQW.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccjIThQW.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccjIThQW.o
/tmp/ccjIThQW.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccjIThQW.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccjIThQW.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccjIThQW.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccjIThQW.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccjIThQW.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//



const int MAX = 100005;
int N,M;
int p[MAX], x[MAX], y[MAX];
int graph[MAX][MAX]; 
bool visit[MAX];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccuv3lT8.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccuv3lT8.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccuv3lT8.o
/tmp/ccuv3lT8.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccuv3lT8.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccuv3lT8.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccuv3lT8.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccuv3lT8.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccuv3lT8.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//



const int MAX = 100005;
int N,M;
int p[MAX], x[MAX], y[MAX];
int graph[MAX][MAX]; 
bool visit[MAX];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
        return;
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccK8eCSe.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccK8eCSe.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccK8eCSe.o
/tmp/ccK8eCSe.o: in function `main':
a.cc:(.text+0x250): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccK8eCSe.o
a.cc:(.text+0x28d): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccK8eCSe.o
a.cc:(.text+0x29b): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccK8eCSe.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccK8eCSe.o
a.cc:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccK8eCSe.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//



const int MAX = 100005;
int N,M;
int p[MAX], x[MAX], y[MAX];
int graph[MAX][MAX]; 
bool visit[MAX];
int ans = 0;

void check(int tmp,int len){
        visit[tmp] = true;
        for(int i = 1; i <= len; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i,len);
        }
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i,N);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/ccwviBUW.o: in function `check(int, int)':
a.cc:(.text+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccwviBUW.o
a.cc:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccwviBUW.o
/tmp/ccwviBUW.o: in function `main':
a.cc:(.text+0x251): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccwviBUW.o
a.cc:(.text+0x28e): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/ccwviBUW.o
a.cc:(.text+0x29c): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccwviBUW.o
a.cc:(.text+0x2a5): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccwviBUW.o
a.cc:(.text+0x2ba): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccwviBUW.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//



const int MAX = 100005;
int N,M;
int p[MAX], x[MAX], y[MAX];
int graph[MAX][MAX]; 
bool visit[MAX];
int ans = 0;

void check(int tmp){
        visit[tmp] = true;
        for(int i = 1; i <= N; i++){
                if(visit[i] == true) continue;
                if(!((graph[tmp][i]))) continue; 
                check(i);
        }
}

int main(){
        cin >> N >> M;
        rep(i,N) cin >> p[i];
        rep(i,M){
                cin >> x[i] >> y[i];
                graph[x[i]][y[i]] = graph[y[i]][x[i]] = 1;
        }

        for(int i = 1; i <= N; i++){
                memset(visit, false, sizeof(visit));

                check(i);
                if(visit[p[i-1]]) ans++;
        }

        cout << ans << endl;
        return 0;
}


Compiler output:
/tmp/cc42Qjco.o: in function `check(int)':
a.cc:(.text+0x13): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc42Qjco.o
a.cc:(.text+0x2c): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc42Qjco.o
/tmp/cc42Qjco.o: in function `main':
a.cc:(.text+0x24c): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc42Qjco.o
a.cc:(.text+0x281): relocation truncated to fit: R_X86_64_PC32 against symbol `visit' defined in .bss section in /tmp/cc42Qjco.o
a.cc:(.text+0x28f): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cc42Qjco.o
a.cc:(.text+0x298): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cc42Qjco.o
a.cc:(.text+0x2ad): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cc42Qjco.o
collect2: error: ld returned 1 exit status
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct UnionFind{
  vi data;
  UnionFind(int N): data(N,-1){}
  int root(int x){
    if(data[x]<0){return x;}else{
      return root(data[x]);
    }
  }

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

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

  vi classes(int N){
    vi ans(N);
    for (int i=0;i<N;++i){
      ans[i]=root(i);
    }
    return ans;
  }
};


int counter(vi& v, vi& w){
  int n=v.size(), m=w.size();
  sort(v.begin(), v.end(), greater<int>());
  sort(w.begin(), w.end(), greater<int>());

  int t=0;
  int count=0;
  for (int s=0;s<m;++s){
    while(v[t]<=w[s]){
      if(v[t]==w[s]){count++;}
      if (t==N-1){break;}
      if(v[t]<w[s]){t++;}
    }
  }

  return count;
}

int main(){
  int N,M;cin>>N>>M;
  vi p;
  for (int i=0;i<N;++i){
    int p_;cin>>p_;p.push_back(p_-1);
  }
  vi x, y;
  for (int i=0;i<M;++i){
    int x_,y_;cin>>x_>>y_;
    x.push_back(x_-1);y.push_back(y_-1);
  }

  UnionFind uf(N);
  for (int i=0;i<M;++i){
    uf.unite(x[i],y[i]);
  }

  vi classes=uf.classes(N);

  vi groups[N];
  vi perms[N];

  for (int i=0;i<N;++i){
    int x=classes[i];
    groups[x].push_back(i);
    perms[x].push_back(i);
  }

  int count=0;
  for (int i=0;i<N;++i){
    count+=counter(groups[i], perms[i]);
  }

  cout << count << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int counter(vi&, vi&)':
a.cc:45:14: error: 'N' was not declared in this scope
   45 |       if (t==N-1){break;}
      |              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct UnionFind{
  vi data;
  UnionFind(int N): data(N,-1){}
  int root(int x){
    if(data[x]<0){return x;}else{
      return root(data[x]);
    }
  }

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

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

  vi classes(){
    vi ans(N);
    for (int i=0;i<N;++i){
      ans[i]=root(i);
    }
    return ans;
  }
};


int counter(vi& v, vi& w){
  int n=v.size(), m=w.size();
  sort(v.begin(), v.end(), greater<int>());
  sort(w.begin(), w.end(), greater<int>());

  int t=0;
  int count=0;
  for (int s=0;s<m;++s){
    while(v[t]<=w[s]){
      if(v[t]==w[s]){count++;}
      if(v[t]<w[s]){t++;}
    }
  }

  return count;
}

int main(){
  int N,M;cin>>N>>M;
  vi p;
  for (int i=0;i<N;++i){
    int p_;cin>>p_;p.push_back(p_-1);
  }
  vi x, y;
  for (int i=0;i<M;++i){
    int x_,y_;cin>>x_>>y_;
    x.push_back(x_-1);y.push_back(y_-1);
  }

  UnionFind uf(N);
  for (int i=0;i<M;++i){
    uf.unite(x[i],y[i]);
  }

  vi classes=uf.classes();

  vi groups[N];
  vi perms[N];

  for (int i=0;i<N;++i){
    int x=classes[i];
    groups[x].push_back(i);
    perms[x].push_back(i);
  }

  int count=0;
  for (int i=0;i<N;++i){
    count+=counter(groups[i], perms[i]);
  }

  cout << count << endl;
  return 0;
}

Compiler output:
a.cc: In member function 'vi UnionFind::classes()':
a.cc:26:12: error: 'N' was not declared in this scope
   26 |     vi ans(N);
      |            ^
Language: Java

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] P = new int[N+1]; // P[i]:整数ｉがある場所（ｉにある整数、ではない）
        for (int i = 1; i <= N; i++){
            int p = sc.nextInt();
            P[p] = i;
        }
        DJSet ds = new DJSet(N+1);
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            ds.union(x, y);
        }
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            if(ds.same(i, P[i]) || i == P[i]) ans++;
        }

        System.out.println(ans);
        sc.close();

    }

}

class DJSet2 {
    /**
     * 各要素の親を保持する配列。
     * 自信が根である要素は負の数を持つ。
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ。
     * @param n 対象となる要素数
     */
    public DJSet2(int n) {
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める。
     * rootを求める過程で経路圧縮しrootが親になるようにする。
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x) {
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する。
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (upper[y] < upper[x]) {
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える。
     * @return 集合の数
     */
    public int countSet() {
        int c = 0;
        for (int u : upper) {
            if (u < 0)
                c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える。
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x) {
        return root(x) * -1;
    }
}

Compiler output:
Main.java:15: error: cannot find symbol
        DJSet ds = new DJSet(N+1);
        ^
  symbol:   class DJSet
  location: class Main
Main.java:15: error: cannot find symbol
        DJSet ds = new DJSet(N+1);
                       ^
  symbol:   class DJSet
  location: class Main
2 errors
Language: C++

#include <iostream>
#include <algorithm>
#include <limits.h>
#include <vector>
#include <map>
#include <string>
#include <tuple>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, m, p[100010], x, y;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> p[i];
    
    int q[100010], r[100010], q_num = 0, inf = 1e6;
    for (int i = 0; i < n; i++) {
        q[i] = inf;  r[i] = 0;
    }
    
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        x--;  y--;
        if (q[x] != inf && q[y] != inf) {
            int m = max(q[x], q[y]);
            for (int j = 0; j < n; j++) {
                if (q[j] == m) q[j] = min(q[x], q[y]);
            }
            r[min(q[x], q[y])] += r[m];
            r[m] = 0;
        }
        else if (q[x] != inf) {
            q[y] = q[x];
            r[q[x]]++;
        }
        else if (q[y] != inf) {
            q[x] = q[y];
            r[q[y]]++;
        }
        else {
            q[x] = q[y] = q_num;
            r[q_num] += 2;
            q_num++;
        }
    }
    
    int tmax = 0;
    for (int i = 0; i < q_num; i++) tmax = max(r[i], tmax);
    
    int s[q_num + 1][tmax], t[tmax];
    for (int i = 0, i < tmax; i++) t[i] = 0;
    for (int i = 0; i < n; i++) {
        s[r[i]][t[i]] = p[i];
        t[i]++;
    }
    
    for (int i = 0; i < q_num; i++) {
        sort(s[i], s[i] + t[i]);
        
    }
    
    
    for (int i = 0; i < n; i++) cout << q[i] << " ";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:22: error: expected ';' before '<' token
   52 |     for (int i = 0, i < tmax; i++) t[i] = 0;
      |                      ^~
      |                      ;
a.cc:52:23: error: expected primary-expression before '<' token
   52 |     for (int i = 0, i < tmax; i++) t[i] = 0;
      |                       ^
Language: C++


#include <bits/stdc++.h>
#include "unionfind.hpp"
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a,T b){
    if (a > b) {
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a,T b){
    if(a < b) {
        a=b;
        return true;
    }
    return false;
}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/

int main(){
    int n,m;
    cin >> n >> m;
    int p[100010];
    rep(i,n)cin >> p[i];
    int x[100010];
    int y[100010];
    rep(i,m)cin >> x[i] >> y[i];
    UnionFind tree(n);  //初期化
    
    rep(i,n)tree.unite(x[i],y[i]);  //グラフの連結
    int cnt=0;
    rep(i,n)if(tree.same(p[i],i))cnt++;
    
    cout << cnt << endl;
    
}

Compiler output:
a.cc:3:10: fatal error: unionfind.hpp: No such file or directory
    3 | #include "unionfind.hpp"
      |          ^~~~~~~~~~~~~~~
compilation terminated.