Language: C++

#include?<iostream>
#include?<vector>
#include?<queue>
#include?<stack>
using?namespace?std;

//?并?集相?数据与算法
#define?MAX_N?100000?+?16
int?parent[MAX_N];
int?height[MAX_N];

void?init(const?int&?n)
{
	for?(int?i?=?0;?i?<?n;?++i)
	{
		parent[i]?=?i;
		height[i]?=?0;
	}
}

int?find(const?int&?x)
{
	if?(parent[x]?==?x)
	{
		return?x;
	}
	else
	{
		return?parent[x]?=?find(parent[x]);
	}
}

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

	if?(height[x]?<?height[y])
	{
		parent[x]?=?y;
	}
	else
	{
		parent[y]?=?x;
		if?(height[x]?==?height[y])
		{
			++height[x];
		}
	}
}

bool?same(const?int&?x,?const?int&?y)
{
	return?find(x)?==?find(y);
}
//?End?Of?并?集

//?原始的?用它来描述
vector<int>?children[MAX_N];
int?parent_tree[MAX_N];
bool?marked[MAX_N];
int?ancestor[MAX_N];
//??条指令被拆分??操作?+?目?
stack<char>?operation;
stack<int>??target;

void?bfs(int?index,?int?the_ancestor)
{
	queue<int>?q_index;
	queue<int>?q_ancestor;
	q_index.push(index);
	q_ancestor.push(the_ancestor);
	while?(!q_index.empty())
	{
		the_ancestor?=?q_ancestor.front();?q_ancestor.pop();
		index?=?q_index.front();?q_index.pop();
		if?(marked[index]?==?true)
		{
			the_ancestor?=?index;
		}
		ancestor[index]?=?the_ancestor;
		for?(vector<int>::iterator?it?=?children[index].begin();?it?!=?children[index].end();?++it)
		{
			q_index.push(*it);
			q_ancestor.push(the_ancestor);
		}
	}
}

int?main(int?argc,?char?*argv[])
{

	int?N,?Q;
	while?(cin?>>?N,?cin?>>?Q,?N)
	{
		for?(int?i?=?0;?i?<?N;?++i)
		{
			children[i].clear();
			marked[i]?=?false;
		}
		marked[0]?=?true;
		int?p;
		for?(int?i?=?1;?i?<?N;?++i)
		{
			cin?>>?p;?--p;
			parent_tree[i]?=?p;
			children[p].push_back(i);
		}
		for?(int?i?=?0;?i?<?Q;?++i)
		{
			char?o;
			int?t;
			cin?>>?o?>>?t;?--t;
			if?(o?==?'M')
			{
				if?(marked[t])
				{
					continue;
				}
				else
				{
					marked[t]?=?true;
				}
			}
			operation.push(o);
			target.push(t);
		}
		bfs(0,?0);
		init(N);
		for?(int?i?=?0;?i?<?N;?++i)
		{
			unite(i,?ancestor[i]);
		}
		unsigned?long?long?result?=?0;
		while?(!operation.empty())
		{
			char?o?=?operation.top();?operation.pop();
			int?t?=?target.top();?target.pop();
			if?(o?==?'Q')
			{
				result?+=?ancestor[find(t)]?+?1;	//??目index从1?始
			}
			else
			{
				//??行“反染色”操作，之后?个?点的祖先??其父?点的祖先
				int?p?=?ancestor[find(parent_tree[t])];
				unite(t,?parent_tree[t]);
				ancestor[find(t)]?=?p;
			}
		}
		cout?<<?result?<<?endl;
	}
	

	return?0;
}

Compiler output:
a.cc:1:9: error: #include expects "FILENAME" or <FILENAME>
    1 | #include?<iostream>
      |         ^
a.cc:2:9: error: #include expects "FILENAME" or <FILENAME>
    2 | #include?<vector>
      |         ^
a.cc:3:9: error: #include expects "FILENAME" or <FILENAME>
    3 | #include?<queue>
      |         ^
a.cc:4:9: error: #include expects "FILENAME" or <FILENAME>
    4 | #include?<stack>
      |         ^
a.cc:8:8: error: macro names must be identifiers
    8 | #define?MAX_N?100000?+?16
      |        ^
a.cc:5:6: error: expected nested-name-specifier before '?' token
    5 | using?namespace?std;
      |      ^
a.cc:9:4: error: expected unqualified-id before '?' token
    9 | int?parent[MAX_N];
      |    ^
a.cc:10:4: error: expected unqualified-id before '?' token
   10 | int?height[MAX_N];
      |    ^
a.cc:12:5: error: expected unqualified-id before '?' token
   12 | void?init(const?int&?n)
      |     ^
a.cc:21:4: error: expected unqualified-id before '?' token
   21 | int?find(const?int&?x)
      |    ^
a.cc:33:5: error: expected unqualified-id before '?' token
   33 | void?unite(int?x,?int?y)
      |     ^
a.cc:56:5: error: expected unqualified-id before '?' token
   56 | bool?same(const?int&?x,?const?int&?y)
      |     ^
a.cc:63:1: error: 'vector' does not name a type
   63 | vector<int>?children[MAX_N];
      | ^~~~~~
a.cc:64:4: error: expected unqualified-id before '?' token
   64 | int?parent_tree[MAX_N];
      |    ^
a.cc:65:5: error: expected unqualified-id before '?' token
   65 | bool?marked[MAX_N];
      |     ^
a.cc:66:4: error: expected unqualified-id before '?' token
   66 | int?ancestor[MAX_N];
      |    ^
a.cc:68:1: error: 'stack' does not name a type
   68 | stack<char>?operation;
      | ^~~~~
a.cc:69:1: error: 'stack' does not name a type
   69 | stack<int>??target;
      | ^~~~~
a.cc:71:5: error: expected unqualified-id before '?' token
   71 | void?bfs(int?index,?int?the_ancestor)
      |     ^
a.cc:94:4: error: expected unqualified-id before '?' token
   94 | int?main(int?argc,?char?*argv[])
      |    ^