57 lines
1004 B
C++
57 lines
1004 B
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
const int N = 1e5 + 10;
|
||
int n;
|
||
|
||
struct Node {
|
||
int sum = 0; // 被操作次数
|
||
int color;
|
||
int ls = -1, rs = -1; // 左儿子与右儿子
|
||
} tr[N];
|
||
|
||
void dfs(int u, int now) {
|
||
now += tr[u].sum;
|
||
if (u == -1)
|
||
return;
|
||
|
||
if (now & 1)
|
||
tr[u].color ^= 1;
|
||
|
||
dfs(tr[u].ls, now), dfs(tr[u].rs, now);
|
||
}
|
||
|
||
int main() {
|
||
#ifndef ONLINE_JUDGE
|
||
freopen("20240602.in", "r", stdin);
|
||
#endif
|
||
// 读入
|
||
int n;
|
||
cin >> n;
|
||
for (int i = 1; i < n; i++) {
|
||
int x;
|
||
cin >> x;
|
||
if (tr[x].ls == -1) // 赋值右儿子
|
||
tr[x].ls = i + 1;
|
||
else // 左儿子
|
||
tr[x].rs = i + 1;
|
||
}
|
||
string s; // 注意:输入的是01串,不是0 1
|
||
cin >> s;
|
||
for (int i = 1; i <= n; i++)
|
||
tr[i].color = s[i - 1] - '0';
|
||
|
||
int q;
|
||
cin >> q;
|
||
|
||
while (q--) {
|
||
int x;
|
||
cin >> x;
|
||
tr[x].sum++;
|
||
}
|
||
dfs(1, 0);
|
||
|
||
for (int i = 1; i <= n; i++)
|
||
printf("%d", tr[i].color);
|
||
return 0;
|
||
}
|