代码:
#include <bits/stdc++.h>
using namespace std;
int n, q;
struct node {
node *father;
bool colour;
} a[100000];
void bfs(int x) {
queue<node>q;
q.push(a[x]);
a[x].colour = !a[x].colour;
while (!q.empty()) {
int flag = 0;
for (int i = 1; i < n; i++) {
if (a[i].father == q.front()) {//编译错误
q.push(a[i]);
a[i].colour = !a[i].colour;
flag++;
if (flag == 2) {
q.pop();
flag = 0;
}
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int x;
cin >> x;
a[i].father = a[x];
}
for (int i = 0; i < n; i++) {
char c;
cin >> c;
a[i].colour = c - '0';
}
cin >> q;
while (q--) {
int swch;
cin >> swch;
bfs(swch);
}
for (int i = 0; i < n; i++) {
cout << a[i].colour;
}
return 0;
}
请问:怎么改才能避免编译错误?