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

#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
const int MAX_N = 100000 + 10;
int N, Q;
int P[MAX_N];
int vis[MAX_N];

void build(int N) {
    for (int i = 0; i <= N; i++)
        P[i] = i;
}

int find(int x) {
    if (vis[P[x]])
        return P[x];
    else
        return find(P[x]);
}

void Unite(int parent, int child) {
    P[child] = parent;
}

int main() {
    while (~scanf("%d %d", &N, &Q) && (N || Q)) {
        memset(vis, 0, sizeof(vis));
        vis[1] = 1;
        build(N);
        int x;
        for (int i = 2; i <= N; i++) {
            scanf("%d", &x);
            Unite(x, i);
        }
        char s;
        long long sum = 0;
        getchar();
        for (int i = 0; i < Q; i++) {
            scanf("%c %d", &s, &x);
            getchar();
            if (s == 'M')
                vis[x] = 1;
            else
                sum += find(x);
        }
        printf("%lld\n", sum);
    }
    return 0;
}

Compiler output:
main.c:1:10: fatal error: algorithm: No such file or directory
    1 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>
#include<string>
#include<cstring>
using namespace std;
const int num = 1e5+1;
int n,q,ask[num][2],time[num]={},askl=0;
int father[num];
bool mark[num]={};
long long getF(int t)
{
    if(mark[t]&&time[t]<=ask[askl][1])
        return (long long)t;
    return (long long)(father[t]=getF(father[t]));
}
int main()
{
    scanf("%d%d",&n,&q);
    char c;
    int x,i,j,fax,t;
    long long ans=0;
    for(i=2;i<=n;++i)
        scanf("%d",&father[i]);
    getchar();
    bool flag=false;
    time[1]=0;
    mark[1]=true;
    while(scanf("%c",&c)&&c!='0'){
        scanf("%d",&x);
        if(c=='M'){
            if(!flag){
                ++t;
                flag=true;
            }
            mark[x]=true;
            time[x]=t;
        }
        else{
            flag=false;
            ++askl;
            ask[askl][0]=x;
            ask[askl][1]=t;
        }
        getchar();
    }
    while(askl>0){
        ans+=getF(ask[askl][0]);
        --askl;
    }
    printf("%lld\n",ans);
    return 0;
}



Compiler output:
main.c:2:9: fatal error: string: No such file or directory
    2 | #include<string>
      |         ^~~~~~~~
compilation terminated.
Language: C

#include<iostream>
using namespace std;
int n,q;
int par[110],Rank[110];
void init()
{
	int i;
    for(i=0;i<110;i++)
    {
        par[i]=i;
        Rank[i]=0;
    }
    Rank[1]=1;
}
int MV(int t)
{
    if(t==1)
        return 1;
    else
        return(t+MV(par[t]));
}
void QV(int t)
{
    cout<<par[t]<<endl;
}
int main()
{
    char f;
    init();
	//freopen("text.txt","r",stdin);
	cin>>n>>q;
	for(int i=2;i<=n;i++)
	{
	    cin>>par[i];
	    Rank[i]=Rank[par[i]]+1;
	}
	for(int i=1;i<=q;i++)
	{
	    int a;
	    cin>>f>>a;
	    if(f=='Q')
            QV(a);
        else if(f=='M')
            cout<<MV(a)<<endl;
	}
	cout<<"0 0"<<endl;
	return 0;
}


Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>
#define maxn 100005
int n,m;
int f[maxn];
char vis[maxn];
int _find(int x)
{
    if(vis[x])
        return x;
    else return _find(f[x]);
}
int main()
{

    
    int i;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(!n&&!m)break;
        long long sum=0;
        for(i=1;i<=n;i++)
        {
            f[i]=i;
        }
        memset(vis,0,sizeof(vis));
        vis[1]=1;
        for(i=1;i<n;i++)
        {
            int ch;
            scanf("%d",&ch);
            f[i+1]=ch;
        }
        for(i=1;i<=m;i++)
        {
            char ch[20];
            scanf("%s",ch);
            if(ch[0]=='Q')
            {
                int t;
                scanf("%d",&t);
縲??縲??縲??縲??縲??縲??for(; !vis[t]; t = f[t]) ;
                sum+=t;
            }
            else
            {
                int t;
                scanf("%d",&t);
                vis[t]=1;

            }
        }
        printf("%lld\n",sum);

    }
    return 0;

}

Compiler output:
main.c: In function 'main':
main.c:25:9: error: implicit declaration of function 'memset' [-Wimplicit-function-declaration]
   25 |         memset(vis,0,sizeof(vis));
      |         ^~~~~~
main.c:2:1: note: include '<string.h>' or provide a declaration of 'memset'
    1 | #include<stdio.h>
  +++ |+#include <string.h>
    2 | #define maxn 100005
main.c:25:9: warning: incompatible implicit declaration of built-in function 'memset' [-Wbuiltin-declaration-mismatch]
   25 |         memset(vis,0,sizeof(vis));
      |         ^~~~~~
main.c:25:9: note: include '<string.h>' or provide a declaration of 'memset'
main.c:41:1: error: '\U00007e32' undeclared (first use in this function)
   41 | 縲??縲??縲??縲??縲??縲??for(; !vis[t]; t = f[t]) ;
      | ^~
main.c:41:1: note: each undeclared identifier is reported only once for each function it appears in
main.c:41:4: error: expected expression before '?' token
   41 | 縲??縲??縲??縲??縲??縲??for(; !vis[t]; t = f[t]) ;
      |    ^
Language: C++


/* 
 author:hdsdogge 
 begin: 
 end: 
 cost: 
 *//*   author 
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<list>
#include <sstream>
#include<ctype.h>
using namespace std;
const int maxn=1000000+10;
typedef pair<int,int> P;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
int T,n,m;
int par[maxn];
int vis[maxn];
int main() {
    //freopen("test","r",stdin);
    //freopen("out","w",stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    while(cin>>n>>m&&(n+m)){
        memset(par,0,sizeof(par));
        memset(vis,0, sizeof(vis));
        par[1]=1;
        vis[1]=1;
        ll ans=0;
        for(int i=2;i<=n;i++){
            int x;
            cin>>x;
            par[i]=x;
        }
        for(int i=0;i<m;i++){
            char c;
            int x;
            cin>>c>>x;
            if(c=='Q'){
                //x=par[x];
                while(vis[x]==0){
                    x=par[x];
                }
                ans+=x;
            }
            else if(c=='M'){
               vis[x]=1;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
} 


Compiler output:
a.cc:7:4: error: unterminated comment
    7 |  *//*   author
      |    ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<cstdio>
#include<stack>
#include<cmath>
#include<bitset>
#include<functional>
#include<memory>
#include<utility>
using namespace std;
#define FOR(i,m,n) for(i=m;i<n;i++)
#define MIN(x,y) (x>y?y:x)
#define ab(x,y) (x>y ?(x-y):(y-x))
#define CLR(a,b) memset(a,b,sizeof(a))
#define ROF(i,m,n) for(i=m;i>=n;i--)
#define BUG cout<<"debug"<<endl;
#define RT return
#define BK break
#define HEAP priority_queue
#define SP " "
#define lowf(a,b,c) lower_bound(a,b,c)
#define upf(a,b,c) upper_bound(a,b,c)
#define CP bool cmp(node A,node B)
#define maxn 100000
typedef long long LL;
typedef vector<int> VI;
const int INF = 2147483647;
const int NEN = -INF - 1;
const LL LINF = 9223372036854775807;
int fa[maxn+5];
int node[maxn + 5];
int N, Q;
int main()
{
	while (1)
	{
		memset(node, 0, sizeof(node));
		cin >> N >> Q; getchar(); getchar();
		if (N == 0 && Q == 0)break;
		int i;
		LL sum = 0;
		char ope;
		int  a;
		FOR(i, 1, N + 1)
		{
			scanf("%d", &fa[i + 1]);
		}
		node[1] = 1;
		while (getchar() != '\n');
		while (Q--)
		{
			scanf("%c", &ope);
			scanf("%d", &a);
			if (ope == 'M')node[a] = 1;
			else
			{
				while (node[fa[a]] != 1)
				{
					a = fa[a];
				}
				sum += fa[a];
			}
		}
		cout << sum << endl;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:17: error: 'memset' was not declared in this scope
   41 |                 memset(node, 0, sizeof(node));
      |                 ^~~~~~
a.cc:14:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   13 | #include<utility>
  +++ |+#include <cstring>
   14 | using namespace std;
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<cstdio>
#include<stack>
#include<memory.h>
#include<cmath>
#include<bitset>
#include<functional>
#include<memory>
#include<utility>
using namespace std;
#define FOR(i,m,n) for(i=m;i<n;i++)
#define MIN(x,y) (x>y?y:x)
#define ab(x,y) (x>y ?(x-y):(y-x))
#define CLR(a,b) memset(a,b,sizeof(a))
#define ROF(i,m,n) for(i=m;i>=n;i--)
#define BUG cout<<"debug"<<endl;
#define RT return
#define BK break
#define HEAP priority_queue
#define SP " "
#define lowf(a,b,c) lower_bound(a,b,c)
#define upf(a,b,c) upper_bound(a,b,c)
#define CP bool cmp(node A,node B)
#define maxn 100000
typedef long long LL;
typedef vector<int> VI;
const int INF = 2147483647;
const int NEN = -INF - 1;
const LL LINF = 9223372036854775807;
int fa[maxn+5];
int node[maxn + 5];
int N, Q;
int main()
{
	while (1)
	{
		memset(node, 0, sizeof(node));
		scanf_s("%d%d", &N, &Q);
		if (N == 0 && Q == 0)break;
		int i;
		unsigned long long sum = 0;
		char ope;
		int  a;
		FOR(i, 1, N + 1)
		{
			scanf_s("%d", &fa[i + 1]);
		}
		node[1] = 1;
		while (Q--)
		{
			scanf_s("%c", &ope);
			scanf_s("%c", &ope);
			scanf_s("%d", &a);
			if (ope == 'M')node[a] = a;
			else
			{
				while (node[a] != a)
				{
					a = fa[a];
				}
				sum += a;
			}
		}
		cout << sum << endl;
	}
}


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

#include <iostream>
using namespace std;
typedef pair<char, int> P;

const int MAX_N = 100000;
const int MAX_Q = 100000;
int N, Q;
int p[MAX_N+5];
bool M[MAX_N+5];
int uf_par[MAX_N+5];
int uf_rank[MAX_N+5];
int mark[MAX_N+5];

void init(int n) {
    for(int i = 0; i < N; i++) {
        uf_par[i] = i;
        uf_rank[i] = 0;
        mark[i] = i;
    }
}

int find(int x) {
    if (uf_pair[x] == x) {
        return x;
    } else {
        return uf_par[x] = find(uf_par[x]);
    }
}

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

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

int main() {
    while(true) {
        cin >> N >> Q;
        if(!N && !Q) break;

        for(int i = 1; i < N; i++) {
            cin >> p[i-1];
            p[i-1]--;
        }
        vector<P> query;
        char qm;
        int num;
        for(int i = 0; i < Q; i++) {
            cin >> qm >> num;
            if(num == 'M') {
                M[num-1] = true;
            }
            query.push_back(P(qm, num));
        }
        
        for(int i = 0; i < N; i++) {
            if(!M[i]) {
                unite(p[i], i);
            }            
        }
        
        int count = 0;
        for(int i = query.size()-1; i >= 0; i++) {
            int n = query[i].second;
            if(query[i].first == 'M') {
                unite(p[n], n);
            } else {
                count += mark[find(n)];
            }
        }
        cout << count << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int find(int)':
a.cc:23:9: error: 'uf_pair' was not declared in this scope; did you mean 'uf_par'?
   23 |     if (uf_pair[x] == x) {
      |         ^~~~~~~
      |         uf_par
a.cc: In function 'bool same(int, int)':
a.cc:45:12: error: 'uf_find' was not declared in this scope
   45 |     return uf_find(x) == uf_find(y);
      |            ^~~~~~~
a.cc: In function 'int main()':
a.cc:57:9: error: 'vector' was not declared in this scope
   57 |         vector<P> query;
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:57:17: error: expected primary-expression before '>' token
   57 |         vector<P> query;
      |                 ^
a.cc:57:19: error: 'query' was not declared in this scope
   57 |         vector<P> query;
      |                   ^~~~~
a.cc: In function 'int find(int)':
a.cc:28:1: warning: control reaches end of non-void function [-Wreturn-type]
   28 | }
      | ^
Language: C++

#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<char, int> P;

const int MAX_N = 100000;
const int MAX_Q = 100000;
int N, Q;
int p[MAX_N+5];
bool M[MAX_N+5];
int uf_par[MAX_N+5];
int uf_rank[MAX_N+5];
int mark[MAX_N+5];

void init(int n) {
    for(int i = 0; i < N; i++) {
        uf_par[i] = i;
        uf_rank[i] = 0;
        mark[i] = i;
    }
}

int find(int x) {
    if (uf_pair[x] == x) {
        return x;
    } else {
        return uf_par[x] = find(uf_par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(uf_rank[x] < uf_rank[y]) {
        uf_par[x] = y;
        mark[y] = mark[x];
    } else {
        uf_par[y] = x;
        if(uf_rank[x] == uf_rank[y]) uf_rank[x]++;
    }
}

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

int main() {
    while(true) {
        cin >> N >> Q;
        if(!N && !Q) break;

        for(int i = 1; i < N; i++) {
            cin >> p[i-1];
            p[i-1]--;
        }
        vector<P> query;
        char qm;
        int num;
        for(int i = 0; i < Q; i++) {
            cin >> qm >> num;
            if(num == 'M') {
                M[num-1] = true;
            }
            query.push_back(P(qm, num));
        }

        for(int i = 0; i < N; i++) {
            if(!M[i]) {
                unite(p[i], i);
            }
        }

        int count = 0;
        for(int i = query.size()-1; i >= 0; i++) {
            int n = query[i].second;
            if(query[i].first == 'M') {
                unite(p[n], n);
            } else {
                count += mark[find(n)];
            }
        }
        cout << count << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int find(int)':
a.cc:24:9: error: 'uf_pair' was not declared in this scope; did you mean 'uf_par'?
   24 |     if (uf_pair[x] == x) {
      |         ^~~~~~~
      |         uf_par
a.cc: In function 'bool same(int, int)':
a.cc:46:12: error: 'uf_find' was not declared in this scope
   46 |     return uf_find(x) == uf_find(y);
      |            ^~~~~~~
a.cc: In function 'int main()':
a.cc:58:9: error: 'vector' was not declared in this scope
   58 |         vector<P> query;
      |         ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:58:17: error: expected primary-expression before '>' token
   58 |         vector<P> query;
      |                 ^
a.cc:58:19: error: 'query' was not declared in this scope
   58 |         vector<P> query;
      |                   ^~~~~
a.cc: In function 'int find(int)':
a.cc:29:1: warning: control reaches end of non-void function [-Wreturn-type]
   29 | }
      | ^
Language: C++

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;


struct node{
  bool marked;
  int parent;
  int num;
};

int main(){
  while(1){
    vector<node> T;
    int n,q;
    scanf("%d%d",&n,&q);
    if(n==0&&q==0){
      return 0;
    }

    node root;
    root.marked = true;
    root.parent = 0;
    root.num = 1;
    T.push_back(root);
    for(int i=2;i<=n;i++){
      int parent;
      cin >> parent;
      T.push_back((child){false,i,parent-1});
    }

    int sum = 0;
    for(int i=0;i<q;i++){
      char q;
      int v;
      cin >> q >> v;
      if(q=='M'){
        T[v-1].marked = true;
      }else{
        node n = T[v-1];
        while(!n.marked){
          n = T[n.parent];
        }
        sum += n.num;
      }
    }
    cout << sum << endl;

  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:20: error: 'child' was not declared in this scope
   37 |       T.push_back((child){false,i,parent-1});
      |                    ^~~~~
Language: C++

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int v[444444], dep[444444], bg[444444], ed[444444];
vector<int> edges[444444];
char st[111];
vector<pair<int, int> > st0;
void build(int k, int l, int r) {
	v[k] = 1;
	if(l != r) {
		build(k + k, l, (l + r) / 2);
		build(k + k + 1, (l + r) / 2 + 1, r);
	}
}
void renew(int k, int l, int r, int ql, int qr, int x) {
	if (qr < l || r < ql) {
		return ;
	}
	if (ql <= l && r <= qr) {
		if (dep[x] > dep[v[k]]) {
			v[k] = x;
		}
		return ;
	}
	int mid = (l + r) / 2;
	renew(k << 1, l, mid, ql, qr, x);
	renew(k << 1 | 1, mid + 1, r, ql, qr, x);
}

int ask(int k, int l, int r, int pos) {
	if (l == r) {
		return v[k];
	}
	int mid = (l + r) / 2;
	int res;
	if (pos <= mid) {
		res = ask(k << 1, l, mid, pos);
	} else {
		res = ask(k << 1 | 1, mid + 1, r, pos);
	}
	if (dep[v[k]] > dep[res]) {
		return v[k];
	} else {
		return res;
	}
}

int main() {
	for(;;) {
		int n, m;
		scanf("%d%d", &n, &m);
		if(!n and !m) {
			break;
		}
		for(int i(1); i <= n; i++) {
			edges[i].clear();
		}
		for(int i(2); i <= n; i++) {
			int x;
			scanf("%d", &x);
			edges[x].push_back(i);
		}
		st0.clear();
		st0.push_back(make_pair(1, 0));
		dep[1] = 0;
		bg[1] = 1;
		int l(1);
		while(!st0.empty()) {
			int v(st0.back().first), p(st0.back().second++);
			if(p != (int)edges[v].size()) {
				st0.push_back(make_pair(edges[v][p], 0));
				dep[edges[v][p]] = dep[v] + 1;
				bg[edges[v][p]] = ++l;
			}else {
				ed[v] = l;
				st0.pop_back();
			}
		}
		build(1, 1, n);
		long long ans(0);
		for(int i(1); i <= m; i++) {
			int x;
			scanf("%s%d", st, &x);
			if(st[0] == 'M') {
				renew(1, 1, n, bg[x], ed[x], x);
			}else {
				ans = ans + ask(1, 1, n, bg[x]);
			}
		}
		printf("%lld\n",ans)
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:93:37: error: expected ';' before '}' token
   93 |                 printf("%lld\n",ans)
      |                                     ^
      |                                     ;
   94 |         }
      |         ~
Language: C++

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

class union_find{
	vector<int> parent;
public:
	vector<int> marked;
	int root(int a){return parent[a]==a||marked[a]?a:(parent[a]=root(parent[a]));}
	union_find(int n):parent(n),marked(n){for(int i=1;i<n;i++)parent[i]=i;}
	int same(int a,int b){return root(a)==root(b);}
	int unite(int a,int b){
		int x=root(a),y=root(b);//if(x==y)return 0;
		parent[x]=y;
		return 1;
	}
};

int main(){
	int N,M;
	for(;scanf("%d%d",&N,&M),N;){
		vector<int>parent(N);
		for(int i=1;i<N;i++)scanf("%d",&parent[i]),parent[i]--;
		union_find uf(N);
		vector<pair<char,int> >query;
		for(int i=0;i<M;i++){
			char s[2];int n;
			scanf("%s%d",s,&n),n--;
			if(*s=='Q'||!uf.marked[n]){
				if(*s=='M')uf.marked[n]=1;
				query.emplace_back(*s,n);
			}
		}
		for(int i=1;i<N;i++)if(!uf.marked[i])uf.unite(i,parent[i]);
		reverse(query.begin(),query.end());
		int R=0;
		for(auto &e:query){
			if(e.first=='Q')R+=uf.root(e.second)+1;
			else uf.marked[e.second]=0,uf.unite(e.second,parent[e.second]);
		}
		printf("%d\n",R);
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:17: error: 'reverse' was not declared in this scope
   35 |                 reverse(query.begin(),query.end());
      |                 ^~~~~~~
Language: C++

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;

struct node{
    int id;
    node* parent;
    int h;
    vector<node*> child;
};
bool com(node* n1,node* n2){
    return n1->id<n2->id;
}
int main(){
    int n,q,p;
    while(cin>>n>>q,n){
        vector<node*>vec;
        vector<node*>marked;
        node* no=new node;
        no->id=1;
        no->parent=no;
        no->h=1;
        vec.push_back(no);
        marked.push_back(no);
        for(int i=2;i<=n;i++){
            cin>>p;
            node* no=new node;
            no->id=i;
            no->parent=vec[p-1];
            no->h=no->parent->h+1;
            vec[p-1]->child.push_back(no);
            vec.push_back(no);
        }
        int ans=0;
        for(int i=0;i<q;i++){
            char que;int num;
            cin>>que>>num;
            if(que=='M'){
                marked.push_back(vec[num-1]);
            }
            else{
                node* pa=vec[num-1]->parent;
                int found=0;
                while(true){
                    int ma=0;
                    sort(marked.begin(),marked.end(),com);
                    if(binary_search(marked.begin(), marked.end(), pa, com)){
                        ma=max(ma,pa->id);
                        found=1;
                    }
                    if(found){
                        ans+=ma;
                        goto next;
                    }
                    if(pa->id==1){
                        goto next;
                    }
                    pa=vec[pa->id]->parent;
                }
                
            next:;
            }
        }
        cout<<ans<<endl;;
        vec.clear();
        marked.clear();
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:21: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   49 |                     sort(marked.begin(),marked.end(),com);
      |                     ^~~~
      |                     sqrt
a.cc:50:24: error: 'binary_search' was not declared in this scope
   50 |                     if(binary_search(marked.begin(), marked.end(), pa, com)){
      |                        ^~~~~~~~~~~~~
Language: C++

/*
 * hujx.cpp
 *
 *  Created on: 2015年5月21日
 *      Author: dell
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
#include<set>
#include<bitset>
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,num) scanf("%d%d%d",&a,&b,&num)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
//#pragma comment(linker,"/STACK:1024000000,1024000000")
int n,m,d;
//#define N 200005
#define M 100010
#define Mod 1000000000
#define p(x,y) make_pair(x,y)
const int MAX_len=550;
int fa[100005];
int find(int x){
	return x==fa[x]?fa[x]:find(fa[x]);
}
int main(){
    while(sfd(n,m)!=EOF && n+m){
    	int x;
    	for(int i=2;i<=n;i++){
    		sf(fa[i]);
    	}
    	fa[1]=1;
    	ll ans=0;
    	char op[5];
    	for(int i=0;i<m;i++){
    		scanf("%s%d",op,&x);
    		if(op[0] == 'Q'){
    			ans += (ll)find(x);
    		}else
    			fa[x] = x;
    	}
    	pfI(ans);
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:12: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   42 | #define ll __int64
      |            ^~~~~~~
a.cc:67:9: note: in expansion of macro 'll'
   67 |         ll ans=0;
      |         ^~
a.cc:72:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   72 |                         ans += (ll)find(x);
      |                         ^~~
      |                         abs
a.cc:76:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   76 |         pfI(ans);
      |             ^~~
a.cc:33:33: note: in definition of macro 'pfI'
   33 | #define pfI(a) printf("%I64d\n",a)
      |                                 ^
Language: C++

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
const int MAXN = 100000 + 10;
int par[MAX];
int Find(int x){
	if (x == par[x])
		return par[x];
	return Find(par[x]);
}
int main(){
	int n, q;
	char ins[10];
	int v;

	while (~scanf("%d%d", &n, &q) && (n || q)){
		long long sum = 0;
		memset(par, 0, sizeof(par));
		par[1] = 1;
		for (int i = 2; i <= n; i++){
			scanf("%d", &par[i]);
		}
		for (int i = 0; i < q; i++){
			scanf("%s%d", ins, &v);
			if (strcmp(ins, "M") == 0){
				par[v] = v;
			}
			else{
				sum += Find(v);
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

Compiler output:
a.cc:7:9: error: 'MAX' was not declared in this scope; did you mean 'MAXN'?
    7 | int par[MAX];
      |         ^~~
      |         MAXN
a.cc: In function 'int Find(int)':
a.cc:9:18: error: 'par' was not declared in this scope
    9 |         if (x == par[x])
      |                  ^~~
a.cc:11:21: error: 'par' was not declared in this scope
   11 |         return Find(par[x]);
      |                     ^~~
a.cc: In function 'int main()':
a.cc:20:24: error: 'par' was not declared in this scope
   20 |                 memset(par, 0, sizeof(par));
      |                        ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 100005;
int par[N], flag[N];
int find(int x)
{
	if (flag[x] == 1)
		return x;
	else
		return find(par[x]);
}
int main()
{
	int n, m;
	char s[10];
	while (~scanf("%d%d", &n, &m))
	{
		__int64 ans;
		ans = (__int64)0;
		if (n == 0 && m == 0)
			break;
		par[1] = 1;
		memset(flag, 0, sizeof(flag));
		flag[1] = 1;
		int i, x;
		for (i = 2; i <= n; i++)
		{
			scanf("%d", &x);
			par[i] = x;
		}
		while (m--)
		{
			scanf("%s%d", s,&x);
			if (s[0] == 'M')
				flag[x] = 1;
			else
				ans += (__int64)find(x);
		}
		printf("%I64d\n", ans);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:17: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
   22 |                 __int64 ans;
      |                 ^~~~~~~
      |                 __ynf64
a.cc:23:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   23 |                 ans = (__int64)0;
      |                 ^~~
      |                 abs
Language: C++

#include <iostream>
#include <stdio.h>
#define maxN 100016

using namespace std;

int par[maxN], rank[maxN];

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

int main()
{
	int n, t, i, j, x;
	__int64 sum;
	char c;
	while (scanf("%d%d", &n, &t) && (n || t))
	{
		par[1] = 1;
		for (i = 2; i <= n; i++)
			scanf("%d", &par[i]);
		getchar();
		for (i = sum = 0; i < t; i++)
		{
			scanf("%c%d%*c", &c, &x);
			if (c == 'Q')
				sum += find(x);
			else
				par[x] = x;
		}
		printf("%I64d\n", sum);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:9: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
   19 |         __int64 sum;
      |         ^~~~~~~
      |         __int64_t
a.cc:27:26: error: 'sum' was not declared in this scope
   27 |                 for (i = sum = 0; i < t; i++)
      |                          ^~~
a.cc:35:35: error: 'sum' was not declared in this scope
   35 |                 printf("%I64d\n", sum);
      |                                   ^~~
Language: C++

#include <iostream>
#include <stdio.h>
#define maxN 100000 + 16

using namespace std;

int par[maxN], mark[maxN];
int qx[maxN], qt[maxN], tt;

int find(int x)
{
	return mark[x] < tt ? x : par[x] = find(par[x]);
}

int main()
{
	int n, t, i, x, nn;
	char c;
	__int64 sum;
	while (scanf("%d%d", &n, &t) && (n || t))
	{
		par[1] = 1;
		mark[1] = 0;
		for (i = 2; i <= n; i++)
		{
			scanf("%d", &x);
			par[i] = x;
			mark[i] = maxN;
		}
		getchar();
		for (i = nn = 1; i <= t; i++)
		{
			scanf("%c%d%*c", &c, &x);
			if (c == 'M')
				mark[x] = i;
			else
			{
				qx[nn] = x;
				qt[nn++] = i;
			}
		}
		for (i = nn - 1, sum = 0; i >= 1; i--)
		{
			tt = qt[i];
			sum += find(qx[i]);
		}
		printf("%I64d\n", sum);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:9: error: '__int64' was not declared in this scope; did you mean '__int64_t'?
   19 |         __int64 sum;
      |         ^~~~~~~
      |         __int64_t
a.cc:42:34: error: 'sum' was not declared in this scope
   42 |                 for (i = nn - 1, sum = 0; i >= 1; i--)
      |                                  ^~~
a.cc:47:35: error: 'sum' was not declared in this scope
   47 |                 printf("%I64d\n", sum);
      |                                   ^~~
Language: C++

#include <iostream>
#define Q 100005
using namespace std;
typedef long long ll;
ll n,q,u,t[Q],p[Q];
bool marked[Q];
char c[Q];

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

int main(){
  while(1){
    cin>>n>>q;
    if(!n&&!q) break;
    for(int i=0;i<n;i++) marked[i]=false;
    for(int i=1;i<n;i++) cin>>u,u--,p[i]=u;
    for(int i=0;i<q;i++){
      cin>>c[i]>>t[i],t[i]--;
      if(c[i]=='M') marked[t[i]]=true;
    }
    marked[0]=true;
    ans=0;
    for(int i=q-1;i>=0;i--){
      if(c[i]=='M') marked[t[i]]=false;
      else ans+=find(t[i])+1;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   25 |     ans=0;
      |     ^~~
      |     abs
Language: C++

#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_N = 100000;

int N, Q;
char Ope[MAX_N];
int Openum[MAX_N], Marked[MAX_N];
vector<int> child[MAX_N];

void mark(int x, int num) {
  if(Marked[x] == x || Marked[x] == num) return;
  Marked[x] = num;
  for(int i = 0; i < child[x].size(); i++){
    mark(child[x][i], num);
  }
}

void solve() {
  int ans = 0;
  memset(Marked, 0, sizeof(Marked))
  for(int i = 0; i < Q; i++){
    char ope = Ope[i];
    int num = Openum[i];
    if(ope == 'M') mark(num, num);
    else if(ope == 'Q') ans += Marked[num]+1;
  }
  printf("%d\n", ans);
}
  
int main()
{
  while(1){
    scanf("%d %d", &N, &Q);
    if(N == 0 && Q == 0) break;
    for(int i = 0; i < N; i++) child[i].clear();
    for(int i = 1; i < N; i++){
      int par;
      scanf("%d", &par);
      child[par].push_back(i);
    }
    for(int i = 0; i < Q; i++){
      scanf("  %c", &Ope[i]);
      scanf("%d", &Openum[i]);
    }
    solve();
  }
  return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:25:36: error: expected ';' before 'for'
   25 |   memset(Marked, 0, sizeof(Marked))
      |                                    ^
      |                                    ;
   26 |   for(int i = 0; i < Q; i++){
      |   ~~~                               
a.cc:26:18: error: 'i' was not declared in this scope
   26 |   for(int i = 0; i < Q; i++){
      |                  ^
Language: C++

#include <cstdio>
#include <iostream>

using namespace std;
     
const int MAX_N = 100001;
     
// int N, Q;
// long long int ans;
// int par[MAX_N]; 
// bool marked[MAX_N];

void init() {
  for (int i = 0; i <= N; i++) {
    par[i] = i;
  }
}

int search(int x) {
  if (marked[x]) return x;
  else return search(par[x]);
}
  
int main()
{
  marked[1] = true;
  while(1){
    int num, N, Q;
    scanf("%d %d", &N, &Q);
    if(N == 0 && Q == 0) break;
    int par[N+1]; 
    bool marked[N+1];
    long long int ans = 0;
    init();
    // ans = 0;
    for(int i = 2; i <= N; i++){
      scanf("%d", &num);
      par[i] = num;
      marked[i] = false;
    }
    for(int i = 0; i < Q; i++){
      scanf(" %c", &Ope);
      scanf("%d", &Openum);
      if (ope == 'M') {
        marked[num] = true;
      }
    
      else if(ope == 'Q'){
        ans += search(num);
      }
    } 
    printf("%lld\n", ans);
  }
  return 0;
}

Compiler output:
a.cc: In function 'void init()':
a.cc:14:24: error: 'N' was not declared in this scope
   14 |   for (int i = 0; i <= N; i++) {
      |                        ^
a.cc:15:5: error: 'par' was not declared in this scope
   15 |     par[i] = i;
      |     ^~~
a.cc: In function 'int search(int)':
a.cc:20:7: error: 'marked' was not declared in this scope
   20 |   if (marked[x]) return x;
      |       ^~~~~~
a.cc:21:22: error: 'par' was not declared in this scope
   21 |   else return search(par[x]);
      |                      ^~~
a.cc: In function 'int main()':
a.cc:26:3: error: 'marked' was not declared in this scope
   26 |   marked[1] = true;
      |   ^~~~~~
a.cc:42:21: error: 'Ope' was not declared in this scope
   42 |       scanf(" %c", &Ope);
      |                     ^~~
a.cc:43:20: error: 'Openum' was not declared in this scope; did you mean 'enum'?
   43 |       scanf("%d", &Openum);
      |                    ^~~~~~
      |                    enum
a.cc:44:11: error: 'ope' was not declared in this scope; did you mean 'popen'?
   44 |       if (ope == 'M') {
      |           ^~~
      |           popen
Language: C++

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>

using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,q;
int par[100005];
vector<int> child[100005];
queue<P> mna;//marked nearest ancestor
int mark[100005];
int query[100005];
int qquery[100005];
int mnalist[100005];
string s;
int ans;
int main()
{
	while(1)
	{
		rep(i,100005)
		{
			mark[i]=0;
			query[i]=0;
			qquery[i]=0;
			child[i].clear();
			par[i]=0;
			mnalist[i]=0;
		}
		ans=0;
		cin>>n>>q;
		if(n==0)break;
		rep(i,n-1)
		{
			cin>>par[i+1];
			par[i+1]--;
			child[par[i+1]].push_back(i+1);
		}
		mark[0]=1;
		rep(i,q)
		{
			cin>>s>>qquery[i];
			qquery[i]--;
			if(s=="M")
			{
				query[i]=1;
				mark[qquery[i]]=1;
			}
		}
		mna.clear();
		mna.push(P(0,0));
		mnalist[0]=0;
		while(!mna.empty())
		{
			P p=mna.front();mna.pop();
			rep(i,child[p.first].size())
			{
				if(mark[child[p.first][i]]==1)
				{
					mnalist[child[p.first][i]]=child[p.first][i];
					mna.push(P(child[p.first][i],child[p.first][i]));
				}
				else
				{
					mnalist[child[p.first][i]]=p.second;
					mna.push(P(child[p.first][i],p.second));
				}
			}
		}
		int person;
		for(int kkk=q-1;kkk>=0;kkk--)
		{
			if(query[kkk]==1)
			{
				mnalist[qquery[kkk]]=mnalist[par[qquery[kkk]]];
			}
			else
			{
				person=mnalist[qquery[kkk]];
				while(person!=mnalist[person])
				{
					person=mnalist[person];
				}
				ans+=(person+1);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:21: error: 'class std::queue<std::pair<int, int> >' has no member named 'clear'
   62 |                 mna.clear();
      |                     ^~~~~
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int lli;
typedef pair<int,bool> P;
int N,Q;
int p[1000000];
bool hoge[10000000];
int q;
char s;

int parent(int x){
  if(hoge[p[x]]==1) return p[x];
  else return parent(p[x]);
}

int main(){
  while(1){
    scanf("%d%d",&N,&Q);
    if(N==0) break;
    memset(p,0,sizeof(p));
    memset(hoge,0,sizeof(hoge));
    p[1]=-1;
    hoge[1]=1;
    lli res=0;
    for(int i=2;i<=N;i++) scanf("%d\n",&p[i]);
    for(int i=0;i<Q;i++) {
      scanf("%c %d\n",&s,&q);
//      printf("%d\n",hoge[q]);
      if(s=='M'){
        hoge[q]=1;
      }
      if(s=='Q'){
        res+=parent(q);
      }
    }

    printf("%lld\n",res);

  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:5: error: 'memset' was not declared in this scope
   23 |     memset(p,0,sizeof(p));
      |     ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<cmath>
  +++ |+#include <cstring>
    5 | using namespace std;
Language: C++

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
using namespace std;
const int N = 100010;
vector<int> edge[N];
vector<int> mark[N], query[N];
int n, m;
int L(int x){return x << 1;}
int R(int x){return x << 1 | 1;}
struct Tree{
	struct node{
		int v;
	}tr[N << 2];
	void build(int a, int b, int x){
		tr[x].v = 0;
		if(a < b){
			int mid = a + b >> 1;
			build(a, mid, L(x));
			build(mid + 1, b, R(x));
		}
	}
	void update(int x){
		tr[x].v = max(tr[L(x)].v, tr[R(x)].v);
	}
	void modify(int x, int a, int b, int pos, int ad){
		if(a == b){
			tr[x].v = ad;
			return;
		}
		int mid = a + b >> 1;
		if(pos <= mid) modify(L(x), a, mid, pos, ad);
		else modify(R(x), mid + 1, b, pos, ad);
		update(x);
	}
	int query(int x, int a, int b, int l, int r){
		if(l <= a && b <= r) return tr[x].v;
		int mid = a + b >> 1;
		if(r <= mid) return query(L(x), a, mid, l, r);
		else if(l > mid) return query(R(x), mid + 1, b, l, r);
		else return max(query(L(x), a, mid, l, r), query(R(x), mid + 1, b, l, r));
	}
}sg;

LL ans = 0;
int list[N];
void dfs(int u, int d){
	list[d] = u;
	//for(int i = 0; i < query[u].size(); i ++){
		int _index = min(m, 50);
		ans = ans + list[sg.query(1, 1, m, 1,  _index)];
	//}
	for(int i = 0; i < mark[u].size(); i ++){
		int _index = mark[u][i];
		sg.modify(1, 1, m, _index, d);
	}
	for(int i = 0; i < edge[u].size(); i ++){
		int v = edge[u][i];
		dfs(v, d + 1);
	}
	//for(int i = 0; i < mark[u].size(); i ++){
		int _index = min(m, 50);
		sg.modify(1, 1, m, _index, 0);
	//}
}
void solve(){
	ans = 0;
	for(int i = 1; i <= n; i ++){
		edge[i].clear();
		query[i].clear();
		mark[i].clear();
	}
	memset(list, 0, sizeof(list));
	for(int i = 2; i <= n; i ++){
		int x;
		scanf("%d", &x);
		edge[x].push_back(i);
	}
	
	mark[1].push_back(1);
	m ++;
	for(int i = 2; i <= m; i ++){
		char str[2];
		int v;
		scanf("%s%d", str, &v);
		if(str[0] == 'Q') query[v].push_back(i);
		else mark[v].push_back(i);
	}
	
	sg.build(1, m, 1);
	dfs(1, 1);
	
	printf("%lld\n", ans);
}
int main(){
	while(scanf("%d%d", &n, &m) == 2 && n + m){
		solve();
	}
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:65:21: error: redeclaration of 'int _index'
   65 |                 int _index = min(m, 50);
      |                     ^~~~~~
a.cc:53:21: note: 'int _index' previously declared here
   53 |                 int _index = min(m, 50);
      |                     ^~~~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn =100000+10;
int n,q;
int par[maxn];
bool mark[maxn];

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

int main(){
    while(scanf("%d%d",&n,&q)!=EOF){
        if(n==0&&q==0) break;
        for(int i=2;i<=n;i++){
            int p;
            scanf("%d",&p);
            par[i]=p;
        }

        memset(mark,0,sizeof(mark));
        mark[1]=1;

        LL sum=0;
        for(int i=0;i<q;i++){
            char op;
            int v;
            cin>>op>>v;
            if(op=='M'){
                mark[v]=1;
            }
            else{
                sum+=find(v);
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:9: error: 'LL' was not declared in this scope
   31 |         LL sum=0;
      |         ^~
a.cc:40:17: error: 'sum' was not declared in this scope
   40 |                 sum+=find(v);
      |                 ^~~
a.cc:43:25: error: 'sum' was not declared in this scope
   43 |         printf("%lld\n",sum);
      |                         ^~~
Language: C++

#include <iostream>
#include <stdio.h>
#include <memory.h>

using namespace std;

const int MAX_N = 100000;
int N;
int Q;
bool marked[MAX_N + 4];
int par[MAX_N + 4];

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

int main() {
    while (scanf("%d %d", &N, &Q) != EOD && N > 0 && Q > 0) {
        memset(marked, 0, sizeof(marked));
        marked[1] = 1;
        int res = 0;
        int x;
        for (int i = 2; i <= N; i++) {
            scanf("%d", &par[i]);
        }
        cin.ignore();
        char operation;
        int node;
        for (int i = 0; i < Q; i++) {
            scanf("%c %d", &operation, &node);
            if (operation == 'Q') {
                res += find(node);
            }
            else {
                marked[node] = 1;
            }
            cin.ignore();
        }
        printf("%d", res);
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:38: error: 'EOD' was not declared in this scope; did you mean 'EOF'?
   21 |     while (scanf("%d %d", &N, &Q) != EOD && N > 0 && Q > 0) {
      |                                      ^~~
      |                                      EOF
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#define MAX 100010
#define INF 1<<20
using namespace std;

vector<int> lis[MAX];

int u[MAX],r[MAX];

bool vis[MAX];

void DFS(int x,int len,int nod){
	vis[x]=true;
	r[x]=len,u[x]=nod;
	for(int i=0;i<lis[x].size();i++){
		if(!vis[lis[x][i]]&&r[lis[x][i]]>len+1){
			DFS(lis[x][i],len+1,nod);
		}
	}
	vis[x]=false;
}

int main(){
	int n,q,z;char w[2];

	while(cin>>n>>q&&n){

	for(int i=1;i<n;i++){
		scanf_s("%d",&z);z--;
		lis[i].push_back(z);
		lis[z].push_back(i);
		r[i]=INF;
	}
	cout<<"#"<<endl;
	long long ans=0;

	DFS(0,0,0);
	while(q--){
		scanf_s("%s%d",w,&z);z--;

		if(w[0]=='M'){
			DFS(z,0,z);
		}
		else{
			ans+=u[z]+1;
		}
	}

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

Compiler output:
a.cc: In function 'int main()':
a.cc:31:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   31 |                 scanf_s("%d",&z);z--;
      |                 ^~~~~~~
      |                 scanf
a.cc:41:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   41 |                 scanf_s("%s%d",w,&z);z--;
      |                 ^~~~~~~
      |                 scanf
Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e5 + 4;
int par[maxn];
int x[1010], y[1010];
int find(int x){
	if(par[x] == x) return x;
	else return find(par[x]);
}
int main(){
	int n, q;
	while(scanf("%d%d", &n, &q)!=EOF){
		if(n == 0 && q == 0) break;
		par[1] = 1;
		for(int i = 2; i <= n; i++){
			scanf("%d", &par[i]);
		}
		ll ans = 0;
		while(q--){
			char s[2];
			int x;
			scanf("%s", s);
			if(s[0] == 'Q'){
				scanf("%d", &x);
				ans += find(x);
			}
			else{
				scanf("%d", &x);
				par[x] = x;
			}
		}
		printf("%lld\n",ans); 
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: 'll' was not declared in this scope
   21 |                 ll ans = 0;
      |                 ^~
a.cc:28:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   28 |                                 ans += find(x);
      |                                 ^~~
      |                                 abs
a.cc:35:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   35 |                 printf("%lld\n",ans);
      |                                 ^~~
      |                                 abs
Language: C++

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

using namespace std;

struct UnionFind{
    vector <int> par;
    UnionFind(int N) : par(N, -1){}
    void unite(int x, int y){
        x = root(x); y = root(y);
        if(x != y){
            par[x] += par[y];
            par[y] = x;
        }
    }
    int root(int x){ return par[x] < 0 ? x : par[x] = root(par[x]);}
    bool same(int x, int y){ return root(x) == root(y);}
};

typedef pair<bool, int> pbt;;
bool marked[100000];
int p[100000];
int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int N, Q, _t;
    char _c;
    while(ifs >> N >> Q && N){
        memset(marked, 0, sizeof(marked));
        marked[0] = true;
        UnionFind uf(N);
        vector<pbt> query;
        
        REP(i, 1, N){
            ifs >> p[i]; --p[i];
        }
        rep(i, Q){
            ifs >> _c >>_t; --_t;
            if(_c == 'Q')
              query.push_back(pbt(1, _t));
            else if(!marked[_t]){
                query.push_back(pbt(0, _t));
                marked[_t] = true;
            }
        }
        rep(i, N)
          if(!marked[i])
            uf.unite(p[i], i);
        ll sum = 0LL;
        for(int i = query.size() - 1; i >= 0; --i){
            int v = query[i].second;
            if(query[i].first)
              sum += uf.root(v) + 1;
            else
              uf.unite(p[v], v);
        }
        cout << sum << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:11: error: 'ifs' was not declared in this scope
   28 |     while(ifs >> N >> Q && N){
      |           ^~~
a.cc:29:9: error: 'memset' was not declared in this scope
   29 |         memset(marked, 0, sizeof(marked));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<algorithm>
  +++ |+#include <cstring>
    4 | 
a.cc:34:13: error: 'i' was not declared in this scope
   34 |         REP(i, 1, N){
      |             ^
a.cc:34:9: error: 'REP' was not declared in this scope
   34 |         REP(i, 1, N){
      |         ^~~
a.cc:37:9: error: 'rep' was not declared in this scope
   37 |         rep(i, Q){
      |         ^~~
a.cc:49:9: error: 'll' was not declared in this scope
   49 |         ll sum = 0LL;
      |         ^~
a.cc:53:15: error: 'sum' was not declared in this scope
   53 |               sum += uf.root(v) + 1;
      |               ^~~
a.cc:57:17: error: 'sum' was not declared in this scope
   57 |         cout << sum << endl;
      |                 ^~~
Language: C++

#include<iostream>
#include<cstdio>

using namespace std;

int n,q;
int tree[100050];

int Find(int x)
{
    if(tree[x]==x)
        return x;
    return Find(tree[x]);
}

int main()
{
    while(scanf("%d %d",&n,&q)==2)
    {
        if(n==0&&q==0)
            break;
        tree[1]=1;
        for(int i=2;i<=n;i++)
            scanf("%d",&tree[i]);
        getchar();
        long long ans=0;
        for(int i=1;i<=q;i++)
        {
            int temp;
            char s[100];
            gets(s);
            sscanf(&s[2],"%d",&temp);
            if(s[0]=='M')
                tree[temp]=temp;
            else if(s[0]=='Q')
                ans+=Find(temp);
        }
        cout<<ans<<endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:13: error: 'gets' was not declared in this scope; did you mean 'getw'?
   31 |             gets(s);
      |             ^~~~
      |             getw