Files
python/GESP/Level6/20240602_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

57 lines
1004 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}