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

#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
using namespace std;
int main()
{
	string s;
	int k,m=0;
	cin>>s>>k;
	vector <string> a;
	rep(i,s.size())
	{
		string tmp="";
		for(int j=i;j<s.size() and j<j+k;j++) tmp.push_back(s[j]),a.push_back(tmp),m++;
	}
	sort(a.begin(),a.end());
	rep(i,m-1) if(a[i]==a[i+1]) k++;
	cout<<a[k-1];
    rt0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:9: error: 'vector' was not declared in this scope
   32 |         vector <string> a;
      |         ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <iostream>
  +++ |+#include <vector>
    5 | //#include <cfloat>
a.cc:32:23: error: expected primary-expression before '>' token
   32 |         vector <string> a;
      |                       ^
a.cc:32:25: error: 'a' was not declared in this scope
   32 |         vector <string> a;
      |                         ^
Language: C++

#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	int K;
	cin>>str>>K;
	priority_queue<string> dicV;
	set<string> dicS
	string tmp="";
	int size = str.size();
	int dicSize=0;
	
	for(int i=0;i<size;++i){
		tmp="";
		for(int j=i;j<size;++j){
			tmp += str[j];
			if(dicS.count(tmp)){
				//入れたことがある
			}else{
				dicV.push( tmp );
				dicS.insert(tmp);
				while(dicV.size()>K){
					dicV.pop();
				}
			}
		}
	}
	
	string ans = dicV.top();
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Compiler output:
a.cc: In function 'void solve()':
a.cc:50:9: error: expected initializer before 'string'
   50 |         string tmp="";
      |         ^~~~~~
a.cc:55:17: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   55 |                 tmp="";
      |                 ^~~
      |                 tm
a.cc:58:28: error: 'dicS' was not declared in this scope; did you mean 'dicV'?
   58 |                         if(dicS.count(tmp)){
      |                            ^~~~
      |                            dicV
Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  string s;int n;cin>>s>>n;
  vector<string>str;
  for(int i=0;i<min((int)s.size(),n);i++){
    for(int k=0;k<s.size()-i;k++){
	str.pb(s.substr(k,i+1));
      }
    }
  }
  sort(str.begin(),str.end());
  int cnt=0,cnt2=0;
  string ans="";
  while(cnt!=n){
    if(ans!=str[cnt2]){
      cnt++;
      ans=str[cnt2];
    }
    cnt2++;
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc:21:7: error: expected constructor, destructor, or type conversion before '(' token
   21 |   sort(str.begin(),str.end());
      |       ^
a.cc:24:3: error: expected unqualified-id before 'while'
   24 |   while(cnt!=n){
      |   ^~~~~
a.cc:31:3: error: 'cout' does not name a type
   31 |   cout<<ans<<endl;
      |   ^~~~
a.cc:32:3: error: expected unqualified-id before 'return'
   32 |   return 0;
      |   ^~~~~~
a.cc:33:1: error: expected declaration before '}' token
   33 | }
      | ^
Language: C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
    int k;
    cin>>s>>k;
	vector<string> v;
	for (int i=0;i<s.size();i++)
    {
		for(int j=1;j<=5;j++)
        {
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cout<<v[k]<<endl;
	//system ("pause");
	return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
    int k;
    cin>>s>>k;
	vector<string>v;
	for (int i=0;i<s.size();i++)
    {
		for(int j=1;j<=5;j++)
        {
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cout<<v[k]<<endl;
	system ("pause");
	return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
    int k;
    cin>>s>>k;
	vector<string>v;
	for (int i=0;i<s.size();i++)
    {
		for(int j=1;j<=5;j++)
        {
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cout<<v[k]<<endl;
	system ("pause");
	return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
    int k;
    cin>>s>>k;
	vector<string>v;
	for (int i=0;i<s.size();i++)
    {
		for(int j=1;j<=5;j++)
        {
			v.push_back(s.substr(i,j));
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	k--;
	cout<<v[k]<<endl;
	cout<<v[k]<<endl;
	system ("pause");
	return 0;
}

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

/*OJ:
  ProblemID:
  Date:
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vtor>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define mp make_pair
#define pb push_back
#define all(n) (n).begin,(n).end
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef vtor<int> vi;
const int INF=1e9+7;
/*_____main part_____*/
string s;
int K;
int main()
{
	cin>>s>>K;
	vector<string> v;
	for (int i=0;i<s.size();i++)
	{
		for (int j=i;j<min((int)s.size(),i+6);j++) 
		v.push_back(s.substr(i,j-i+1));
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[K-1]<<endl;
	return 0;
}

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

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare_char(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
}

int fact_cal(int L){
    int fact = 1;
    for(int i=1; i<=L; ++i) fact = fact * i;
    return fact;
}

int main(void){
    char s[5050];
    int K;
    scanf("%s %d",s,&K);

    char substr[K+1][strlen(s)+1];
    char a[strlen(s)],b[strlen(s)],tmp[strlen(s)];
    int count = 0;
    strcpy(b,"z");
    for(int j=0;j<strlen(s)-1;j++) strcat(b,"z");
    for(int i=0;i<K+1;i++){
        strcpy(substr[i],b);
    }

    for(int i = 0; i < strlen(s); i++){
        for(int j = i; j < strlen(s);j++){
            a[0] = '\0';
            strncpy(a,s+i,j+1-i);
            a[j+1-i]='\0';
            strcpy(substr[K],a);
            for(int l=1;l<K+1;l++){
                for(int k=1;k<K+1;k++){
                    if(strcmp(substr[k-1], substr[k]) == 0){
                        strcpy(substr[k],b);
                    }
                    if(strcmp(substr[k-1], substr[k])>0){
                        strcpy(tmp, substr[k-1]);
                        strcpy(substr[k-1], substr[k]);
                        strcpy(substr[k], tmp);
                    }
                }
            }
        }
    }
    printf("%s\n",substr[i]);

    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:49:26: error: 'i' undeclared (first use in this function)
   49 |     printf("%s\n",substr[i]);
      |                          ^
main.c:49:26: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

s = input()
k = int(input())
sub = set([])
L = len(s)
for i in range(L) :
    for j in range(1, k+1) :
        if i + j <= L :
            sub.add(s[i:i+j])

sub = list(sub)
sub.sort()
print(sub[k-1])

Compiler output:
a.cc:1:1: error: 's' does not name a type
    1 | s = input()
      | ^
Language: C++

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

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

    vector<string> v;
    for(int i = 0; i < s.size(); ++i){
        string cur;
        for(int j = i; j < s.size(); ++j){
            cur.push_back(s[j]);
            v.push_back(cur); } }

    int k;
    cin >> k;

    auto it = begin(v) + min(v.size(), k * s.size() + 10);
    partial_sort(begin(v), it, end(v));
    unique(begin(v), it);

    cout << v[k - 1] << endl;
    return 0; }


Compiler output:
a.cc: In function 'int main()':
a.cc:21:5: error: 'partial_sort' was not declared in this scope
   21 |     partial_sort(begin(v), it, end(v));
      |     ^~~~~~~~~~~~
a.cc:22:5: error: 'unique' was not declared in this scope
   22 |     unique(begin(v), it);
      |     ^~~~~~
Language: C++

#include <algorithm>
//#include <cstdio>
//#include <functional>
//#include <bits/stdc++.h>
#include <iostream>
//#include <cfloat>
//#include <climits>
#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
#define LL long long

using namespace std;

int main()
{
	string s;
	int k;
	vector<string> buf;
	
	cin>>s;
	cin>>k;
	int len=s.size();
	for(int i=0;i<len;i++) {
		for(int j=1;j<=5;j++) {
			if(i+j>len) break;
			string temp=s.substr(i,j);
			buf.push_back(temp);
		}
	}
	sort(buf.begin(),buf.end());
	
	int count=1;
	if(k==1){
		cout<<buf[0];
		rt0;
	}
	for(int j=1;j<buf.size();j++){
		if(buf[j]==buf[j-1]) continue;
		if(++count==k){
			cout<<buf[j];
			rt0;
		}		
	}
	
	
    rt0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:9: error: 'vector' was not declared in this scope
   31 |         vector<string> buf;
      |         ^~~~~~
a.cc:9:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    8 | #include <cstdlib>
  +++ |+#include <vector>
    9 | //#include <cstring>
a.cc:31:22: error: expected primary-expression before '>' token
   31 |         vector<string> buf;
      |                      ^
a.cc:31:24: error: 'buf' was not declared in this scope
   31 |         vector<string> buf;
      |                        ^~~
Language: C++

#include <iostream>
#include <list>

using namespace std;

int main(){
	string s;
	int K;
	string ksub;
	list<string> matrix;
	for (int i = 0; i < 5; i++){
		matrix.push_front("");
	}
	
	cin >> s >> K;
	int i;
	if (s.length() >= 5){ 
		for (i = 0; i < s.length() - 4; i++){
			for (int j = 1; j <= 5; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
		
		for (; i < s.length(); i++){
			for (int j = 1; j <= s.length() - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
	}else{
		for (i = 0; i < s.length(); i++){
			for (int j = 1; j <= s.length() - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
	}
	
	
	
	cout << matrix[K - 1];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:23: error: no match for 'operator[]' (operand types are 'std::__cxx11::list<std::__cxx11::basic_string<char> >' and 'int')
   57 |         cout << matrix[K - 1];
      |                       ^
Language: C++

#include <iostream>
#include <list>

using namespace std;

int main(){
	string s;
	int K;
	string ksub;
	list<string> matrix;
	for (int i = 0; i < 5; i++){
		matrix.push_front("");
	}
	
	cin >> s >> K;
	int i;
	if (s.length() >= 5){ 
		for (i = 0; i < s.length() - 4; i++){
			for (int j = 1; j <= 5; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
		
		for (; i < s.length(); i++){
			for (int j = 1; j <= s.length - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
	}else{
		for (i = 0; i < s.length(); i++){
			for (int j = 1; j <= s.length - i; j++){
				string temp = s.substr(i, j);
				for (auto itr = matrix.begin(); itr != matrix.end(); itr++){
					if (temp.compare(*itr) < 0){
						matrix.insert(itr, temp);
						matrix.pop_back();
					}
				}
			}
		}
	}
	
	
	
	cout << matrix[k - 1];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:48: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   31 |                         for (int j = 1; j <= s.length - i; j++){
      |                                              ~~^~~~~~
      |                                                      ()
a.cc:43:48: error: invalid use of member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]' (did you forget the '()' ?)
   43 |                         for (int j = 1; j <= s.length - i; j++){
      |                                              ~~^~~~~~
      |                                                      ()
a.cc:57:24: error: 'k' was not declared in this scope
   57 |         cout << matrix[k - 1];
      |                        ^
Language: C++

#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;

int main() {
	string s;
	cin >> s;
	int K;
	cin >> K;
	vector<string> v;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 1; j <= K; j++) {
			if (i + j > s.size()) break;
			v.push_back(s.substr(i, j));
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end);
	cout << v[K - 1] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:16: error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::erase(__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >, <unresolved overloaded function type>)'
   19 |         v.erase(unique(v.begin(), v.end()), v.end);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; iterator = std::vector<std::__cxx11::basic_string<char> >::iterator; const_iterator = std::vector<std::__cxx11::basic_string<char> >::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; iterator = std::vector<std::__cxx11::basic_string<char> >::iterator; const_iterator = std::vector<std::__cxx11::basic_string<char> >::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:52: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'std::vector<std::__cxx11::basic_string<char> >::const_iterator'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |                                     ~~~~~~~~~~~~~~~^~~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXS (5000 + 5)
#define MAXN (25000000 + 5)
#define MAXC (26)
#define cint const int 
#define rint register int
#define LL long long
#define pii pair<int, int>
using namespace std;
cint root = 0;
struct node
{
	int sum, next[MAXC], is_end, fa;
	node(): sum(0), is_end(0)
	{ memset(next, -1, sizeof(next)); }
}b[MAXN];
void update(int dq)
{
	b[dq].sum = b[dq].is_end;
	for (int i = 0; i < MAXC; i++)
		if (b[dq].next[i] != -1)
			b[dq].sum += b[b[dq].next[i]].sum;
}
void ins(char* s, int n)
{
	static int cnt = 0;
	int dq = root;
	for (int i = 0; i < n; i++)
	{
		int& x = b[dq].next[s[i] - 'a'];
		if (x == -1)
			x = ++cnt;
		b[x].fa = dq;
		dq = x;
	}
	b[dq].is_end = 1;
	for (; dq != root; dq = b[dq].fa)
		update(dq);
	update(root);
}
void solve(int dq, int k)
{
	if (b[dq].is_end == 1 && k == 1)
		return ;
	int dqs = b[dq].is_end;
	for (int i = 0; i < MAXC; i++)
	{
		if (b[dq].next[i] != -1 && dqs + b[b[dq].next[i]].sum >= k)
		{
			printf("%c", 'a' + i);
			solve(b[dq].next[i], k - dqs);
			return ;
		}
		if (b[dq].next[i] != -1)
			dqs += b[b[dq].next[i]].sum;
	}
}
int main()
{
	char s[MAXS];
	int k, n;
	scanf("%s%d", s, &k);
	n = strlen(s);
	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++)
			ins(s + i, j - i + 1);
	solve(root, k);
	puts("");
	return 0;
}

Compiler output:
/tmp/cc0opCgY.o: in function `ins(char*, int)':
a.cc:(.text+0x168): relocation truncated to fit: R_X86_64_PC32 against `.bss'
a.cc:(.text+0x171): relocation truncated to fit: R_X86_64_PC32 against `.bss'
a.cc:(.text+0x177): relocation truncated to fit: R_X86_64_PC32 against `.bss'
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  vector<string>ss;
  int n,m;
  string str;
  cin>>str;
  cin>>n;
  int cnt=0;
  string mi="z";
  string mae;
  if(n>=str.size()){
    vector<string>s;
    while(cnt!=n){
      for(int i=0;i<str.size()-cnt;i++){
	bool flag=true;
	for(int j=0;j<s.size();j++)
	  if(s[j]==str.substr(i,cnt+1))
	    flag=false;
	if(flag)s.pb(str.substr(i,cnt+1));
      }
      cnt++;
    }
    sort(s.begin(),s.end());
    cout<<s[n-1]<<endl;
  }else{
  for(int i=0;i<str.size()-1;i++){
    if(mi[0]>str[i]){
      mi=str[i];
    }
  }
  mae=mi;
  if(n==1&&mi[0]>str[str.size()-1]){cout<<str[str.size()-1]<<endl;return 0;}
  if(n==1){cout<<mi<<endl;return 0;}
  mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,1))==0){
      if(mi[1]>str[i+1])mi[1]=str[i+1];
    }
  }
  string mi2=mi;
  for(int i=str.size()-4;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  for(int i=str.size()-3;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  for(int i=str.size()-2;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  ss.pb(mi);
  sort(ss.begin(),ss.end());
  if(n==2){cout<<s[0]<<endl;return 0;}
  mae=mi;mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,2))==0){
      if(mi[2]>str[i+2])mi[2]=str[i+2];
    }
  }
  mi2=mi;
  ss.clear();
  for(int i=str.size()-4;i<str.size()-2;i++){
     ss.pb(str.substr(i,3));
  }
  for(int i=str.size()-3;i<str.size()-2;i++){
    ss.pb(str.substr(i,3));
  }
  ss.pb(mi);
  sort(ss.begin(),ss.end());
  if(n==3){cout<<ss[0]<<endl;return 0;}
  mae=mi;mi=mi+'z';
  ss.clear();
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,3))==0){
      if(mi[3]>str[i+3])mi[3]=str[i+3];
    }
  }
  mi2=mi;
  for(int i=str.size()-4;i<str.size()-3;i++){
 
    ss.pb(str.substr(i,2));
  }
  ss.pb(mi);
  sort(ss.begin(),ss.end());
  if(n==4){cout<<ss[0]<<endl;return 0;}
  mae=mi;mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,4))==0){
      if(mi[4]>str[i+4])mi[4]=str[i+4];
    }
  }
  if(n==5){cout<<mi<<endl;return 0;}
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:18: error: 's' was not declared in this scope
   62 |   if(n==2){cout<<s[0]<<endl;return 0;}
      |                  ^
Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  vector<string>ss;
  int n,m;
  string str;
  cin>>str;
  cin>>n;
  int cnt=0;
  string mi="z";
  string mae;
  if(n>=str.size()){
    vector<string>s;
    while(cnt!=n){
      for(int i=0;i<str.size()-cnt;i++){
	bool flag=true;
	for(int j=0;j<s.size();j++)
	  if(s[j]==str.substr(i,cnt+1))
	    flag=false;
	if(flag)s.pb(str.substr(i,cnt+1));
      }
      cnt++;
    }
    sort(s.begin(),s.end());
    cout<<s[n-1]<<endl;
  }else{
  for(int i=0;i<str.size()-1;i++){
    if(mi[0]>str[i]){
      mi=str[i];
    }
  }
  mae=mi;
  if(n==1&&mi[0]>str[str.size()-1]){cout<<str[str.size()-1]<<endl;return 0;}
  if(n==1){cout<<mi<<endl;return 0;}
  mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,1))==0){
      if(mi[1]>str[i+1])mi[1]=str[i+1];
    }
  }
  string mi2=mi;
  for(int i=str.size()-4;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  for(int i=str.size()-3;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  for(int i=str.size()-2;i<str.size()-1;i++){
    ss.pb(str.substr(i,2));
  }
  ss.pb(mi);
  sort(ss.begin(),ss.end());
  if(n==2){cout<<s[0]<<endl;return 0;}
  mae=mi;mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,2))==0){
      if(mi[2]>str[i+2])mi[2]=str[i+2];
    }
  }
  mi2=mi;
  ss.clear();
  for(int i=str.size()-4;i<str.size()-2;i++){
     ss.pb(str.substr(i,3));
  }
  for(int i=str.size()-3;i<str.size()-2;i++){
    ss.pb(str.substr(i,3));
  }
  ss.pb(mi);
  sort(ss.begin(),ss.end());
  if(n==3){cout<<ss[0]<<endl;return 0;}
  mae=mi;mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,3))==0){
      if(mi[3]>str[i+3])mi[3]=str[i+3];
    }
  }
  mi2=mi;
  for(int i=str.size()-4;i<str.size()-3;i++){
    if(mi2.compare(str.substr(i,2))>0)
      mi2=str.substr(i,2);
  }
  if(n==4&&mi!=mi2){cout<<mi2<<endl;return 0;}
  if(n==4){cout<<mi<<endl;return 0;}
  mae=mi;mi=mi+'z';
  for(int i=0;i<str.size()-4;i++){
    if(mae.compare(str.substr(i,4))==0){
      if(mi[4]>str[i+4])mi[4]=str[i+4];
    }
  }
  if(n==5){cout<<mi<<endl;return 0;}
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:18: error: 's' was not declared in this scope
   62 |   if(n==2){cout<<s[0]<<endl;return 0;}
      |                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


string s;
int n;
map<string,bool> mp;

int main(){
  cin>>s>>n;
  int m=s.size();

  rep(i,m){
    string t={};
    FOR(j,m){
      t =t+s[j];
      mp[t]=true;
    }
  }

  int c=0;

  for(auto itr=mp.begin();itr!=mp.end();itr++,c++){
    if(c==n-1){
      cout<<itr->first<<endl;
    }
  }

  return 0;
}



Compiler output:
a.cc:28:12: error: macro "FOR" requires 3 arguments, but only 2 given
   28 |     FOR(j,m){
      |            ^
a.cc:9:9: note: macro "FOR" defined here
    9 | #define FOR(i,m,n) for(int i=m;i<n;i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:28:5: error: 'FOR' was not declared in this scope
   28 |     FOR(j,m){
      |     ^~~
Language: C++

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

int main() {

    string s;
    int k;

    cin >> s >> k;

    vector< string > v;
    for(int i = 'a'; i <= 'z'; i++) {
        for(int j = 0; j < s.size(); j++) {
            if(s[j] == i) {
                for(int k = 0; j + k < s.size(); k++) {
                    v.push_back(s.substr(j, k + 1));
                    //cout << s.substr(j, k + 1) << endl;
                }
            }
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        if(v.size() >= k) {
            cout << v[k - 1] << endl;
            return 0;
        }
    }
}


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

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;
const int maxn = 5e4 + 10;
char s[maxn];
int k,cnt = 0;
string str[maxn];

int main()
{
    scanf("%s%d",s,&k);
    int len = strlen(s);
    for(int i=0;s[i];i++){
        string ss = "";
        for(int j=0;j<9;j++){
            if(i+j>=len) break;
            ss += s[j+i];
            str[cnt++] = ss;
        }
    }
    sort(str, str+cnt);
    int ct = 1;
    for(int i=1;i<cnt;i++) {
        if(ct==k){
            cout<<str[i-1]<<endl;
            break;
        }
        if(str[i-1]!=str[i]) ct++;
    }
    
    return 0;
}


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

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

using namespace std;

int main()
{
    string s;
    vector<string> v;
    int k;

    cin >> s >> k;

    v.push_back(s.substr(0, 1));
    for (int i = 1; i < s.length(); i++) {
        v.push_back(s.substr(i, 1));
        v.push_back(s.substr(i - 1, 2));
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end(), v.end()));

    cout << v[k - 1];

    return 0;
}


Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 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/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >; _Compare = __gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >]':
/usr/include/c++/14/bits/stl_algo.h:869:20:   required from '_ForwardIterator std::__unique(_ForwardIterator, _ForwardIterator, _BinaryPredicate) [with _ForwardIterator = __gnu_cxx::__normal_iterator<__cxx11::basic_string<char>*, vector<__cxx11::basic_string<char> > >; _BinaryPredicate = __gnu_cxx::__ops::_Iter_comp_iter<__gnu_cxx::__normal_iterator<__cxx11::basic_string<char>*, vector<__cxx11::basic_string<char> > > >]'
  869 |         if (!__binary_pred(__dest, __first))
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:933:27:   required from '_FIter std::unique(_FIter, _FIter, _BinaryPredicate) [with _FIter = __gnu_cxx::__normal_iterator<__cxx11::basic_string<char>*, vector<__cxx11::basic_string<char> > >; _BinaryPredicate = __gnu_cxx::__normal_iterator<__cxx11::basic_string<char>*, vector<__cxx11::basic_string<char> > >]'
  933 |       return std::__unique(__first, __last,
      |              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
  934 |                            __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:23:19:   required from here
   23 |     v.erase(unique(v.begin(), v.end(), v.end()));
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: no match for call to '(__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >) (std::__cxx11::basic_string<char>&, std::__cxx11::basic_string<char>&)'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
Language: C++

/* 2018-05-12-17.41.09*/

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

struct wunionfind
{
    int id[N],sz[N];
    void initial(int n)
    {
        int i;
        for(i=0;i<=n;i++) id[i]=i,sz[i]=1;
    }
    int root(int idx)
    {
        int i=idx;
        while(i!=id[i]) id[i]=id[id[i]],i=id[i];
        return i;
    }
    void uni(int a,int b)
    {
        int i=root(a),j=root(b);
        if (i!=j)
        {
            if(sz[i]>=sz[j]) id[j]=i,sz[i]+=sz[j],sz[j]=0;
            else id[i]=j,sz[j]+=sz[i],sz[i]=0;
        }
    }
    bool check(int a,int b)
    {
        if(root(a)==root(b)) return true;
        else return false;
    }
}W;

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int I[n+1];
    for(int i=1;i<=n;i++)
    {
        int temp;
        scanf("%d",&temp);
        p[temp]=i;
    }
    W.initial(n);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        W.uni(x,y);
    }
    int cnt=0;
    for(int i=1;i<=n;i++) if(W.check(i,I[i])) cnt++;
    printf("%d\n",cnt);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:9: error: 'p' was not declared in this scope
   47 |         p[temp]=i;
      |         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<string>v;
int main()
{
	string s;
	int k;
	cin>>s>>k;
	for(int i=0;i<s.size()-1;i++)
		for(int j=1;j+i<=s.size();j++)v.push_back(s.substr(i,j));
	sort(v.begin(),v.end);
	if(k==1)
	{
		cout<<v[0];
		return 0;
	}
	int js=1;
	for(int i=1;i<v.size();i++)
	{
		if(v[i]!=v[i-1])
			js++;
		if(js==k)
		{
			cout<<v[i];
			return 0;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:13: error: no matching function for call to 'sort(std::vector<std::__cxx11::basic_string<char> >::iterator, <unresolved overloaded function type>)'
   11 |         sort(v.begin(),v.end);
      |         ~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<__cxx11::basic_string<char>*, vector<__cxx11::basic_string<char> > >]'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:63: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*, std::vector<std::__cxx11::basic_string<char> > >'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |                                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   candidate expects 3 arguments, 2 provided
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int k;
	cin>>s>>k;
	for(int i=0;i<s.size()-1;i++)
		for(int j=1;j+i<s.size();j++)v.push_back(s.substr(i,j));
	sort(v.begin(),v.end);
	if(k==1)
	{
		cout<<v[0];
		return 0;
	}
	int js=1;
	for(int i=1;i<v.size();i++)
	{
		if(v[i]!=v[i-1])
			js++;
		if(js==k)
		{
			cout<<v[i];
			return 0;
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:46: error: 'v' was not declared in this scope
    9 |                 for(int j=1;j+i<s.size();j++)v.push_back(s.substr(i,j));
      |                                              ^
a.cc:10:14: error: 'v' was not declared in this scope
   10 |         sort(v.begin(),v.end);
      |              ^
Language: C++

1 #include <bits/stdc++.h>
  2 using namespace std;
  3 
  4 #define _ << " _ " <<
  5 #define TRACE(x) cout << #x << " = " << x << endl
  6 
  7 set<string> s;
  8 string a;
  9 int k;
 10 
 11 int main() {
 12     ios_base::sync_with_stdio(false);
 13     cin.tie(0);
 14 
 15     cin >> a;
 16     cin >> k;
 17 
 18     for (int i = 0; i < a.length(); i++) {
 19         for (int j = 1; j <= 5; j++)
 20             s.insert(a.substr(i, j));
 21     }
 22 
 23     for (int i = 0; i < k - 1; i++) {
 24         string b = *s.begin();
 25         s.erase(b);                                                                                 
 26     }
 27 
 28     cout << *s.begin();
 29 
 30     return 0;
 31 }


Compiler output:
a.cc:1:3: error: stray '#' in program
    1 | 1 #include <bits/stdc++.h>
      |   ^
a.cc:4:5: error: stray '#' in program
    4 |   4 #define _ << " _ " <<
      |     ^
a.cc:5:5: error: stray '#' in program
    5 |   5 #define TRACE(x) cout << #x << " = " << x << endl
      |     ^
a.cc:5:30: error: stray '#' in program
    5 |   5 #define TRACE(x) cout << #x << " = " << x << endl
      |                              ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 1 #include <bits/stdc++.h>
      | ^
a.cc:3:3: error: expected unqualified-id before numeric constant
    3 |   3
      |   ^
a.cc:8:3: error: expected unqualified-id before numeric constant
    8 |   8 string a;
      |   ^
a.cc:9:3: error: expected unqualified-id before numeric constant
    9 |   9 int k;
      |   ^
a.cc:10:2: error: expected unqualified-id before numeric constant
   10 |  10
      |  ^~
Language: C++

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int NX = 1e5 + 5;

int N, M;
vector<int> adj[NX];
int visit[NX], p[NX];

vector<int> num;
map<int, int> pos;

void dfs(int node) {
    if(visit[node])
        return;
    visit[node] = 1;
    num.pb(p[node]);
    pos[node] = 1;
    for(int x: adj[node]) {
        dfs(x);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;

    REP(i, 0, N) {
        cin >> p[i];
        --p[i];
    }

    REP(i, 0, M) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int res = 0;
    REP(i, 0, N) {
        if(!visit[i]) {
            pos.clear();
            num.clear();
            dfs(i);
            for(int x: num) 
                if(pos[x]) ++res;
        }
    }
    cout << res << "\n";
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:30:8: error: reference to 'visit' is ambiguous
   30 |     if(visit[node])
      |        ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:24:5: note:                 'int visit [100005]'
   24 | int visit[NX], p[NX];
      |     ^~~~~
a.cc:32:5: error: reference to 'visit' is ambiguous
   32 |     visit[node] = 1;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:24:5: note:                 'int visit [100005]'
   24 | int visit[NX], p[NX];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:59:13: error: reference to 'visit' is ambiguous
   59 |         if(!visit[i]) {
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:24:5: note:                 'int visit [100005]'
   24 | int visit[NX], p[NX];
      |     ^~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
  int N,M; cin>>N>>M;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  UnionFind Onion(M);
  for(int i=0;i<M;i++){
    int a,b; cin>>a>>b; Onion.unite(a-1,b-1);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(same(i,A[i]-1))ans++;
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:8: error: 'same' was not declared in this scope
   38 |     if(same(i,A[i]-1))ans++;
      |        ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int par[110000];
int r[110000];

void init(int n) {
    rep(i, n) {
        par[i] = i;
        r[i] = 0;
    }
}

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) par[x] = y;
    else {
        par[y] = x;
        if(r[x] == r[y]) r[x]++;
    }
}

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

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> p(n); rep(i, n) cin >> p[i];
    init(110000);
    rep(i, m) {
        ll x, y; cin >> x >> y; x--; y--;
        unite(p[x], p[y]);
    }
    ll ans = 0;
    rep(i, n) if(same(p[i], p[p[i]]) ans++;
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:37: error: expected ';' before 'ans'
   54 |     rep(i, n) if(same(p[i], p[p[i]]) ans++;
      |                                     ^~~~
      |                                     ;
a.cc:55:24: error: expected ')' before ';' token
   55 |     cout << ans << endl;
      |                        ^
      |                        )
a.cc:54:17: note: to match this '('
   54 |     rep(i, n) if(same(p[i], p[p[i]]) ans++;
      |                 ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct UnionFind {
  vector<int> par;
  vector<int> rank;

  UnionFind(int n):par(n),rank(n){
    rep(i,n){
      par[i]=i;
      rank[i]=0;
    }
  }

  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(rank[x]<rank[y]){
      par[x]=y;
    }else{
      par[y]=x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

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

  void body(){
    rep(i,par.size()){
      cout <<par[i]<<" "<<rank[i]<<endl;
    }
  }
};

int main() {
  int n,m,count=0;
  cin >>n>>m;
  vector<int> p(n);
  UnionFind uni(n);
  rep(i,n){
    int w;
    cin >> w;
    p[i]=w-1;
  }
  rep(i,m){
    int x,y;
    cin >>x>>y;
    uni.unite(x-1,y-1);
  }
  rep(i,n){
    if(p[i]==i){
      count++;
      continue;
    }
    for(int j=i+1;j<n;j++)
      if(uni.same(i,j)&&p[j]==i){
        count++;
        break;
      }
    }
  }
  cout << count<<endl;
}

Compiler output:
a.cc:77:3: error: 'cout' does not name a type
   77 |   cout << count<<endl;
      |   ^~~~
a.cc:78:1: error: expected declaration before '}' token
   78 | }
      | ^
Language: C++

#include<iostream>
#include<vector>

struct union_find{
  int n;
  std::vector<int> par;
  union_find(){}
  union_find(int _n):n(_n),par(n,-1){}
  int root(int k){
    if(par[k]<0)return k;
    return par[k] = root(par[k]);
  }
  int unite(int u,int v){
    u = root(u);
    v = root(v);
    if(u==v)return;
    par[u] += par[v];
    par[v] = u;
  }
  bool same(int u,int v){return root(u)==root(v);}
};

signed main(){
  int n,m;
  std::cin>>n>>m;
  std::vector<int> p(n);
  for(auto& pi:p)std::cin>>pi,pi--;
  union_find uni(n);
  for(int _=0;_<m;++_){
    int a,b;
    std::cin>>a>>b;
    a--;b--;
    uni.unite(p[a],p[b]);
  }
  int ans = 0;
  for(int i=0;i<n;++i)if(!uni.same(p[i],i))ans++;
  std::cout<< ans <<std::endl;
}

Compiler output:
a.cc: In member function 'int union_find::unite(int, int)':
a.cc:16:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
   16 |     if(u==v)return;
      |             ^~~~~~
a.cc:18:12: warning: control reaches end of non-void function [-Wreturn-type]
   18 |     par[v] = u;