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

55 lines
946 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 color;
int ls = -1, rs = -1; // 左儿子与右儿子
} tr[N];
void dfs(int u) {
if (u == -1)
return;
if (tr[u].color == 0)
tr[u].color = 1;
else
tr[u].color = 0;
dfs(tr[u].ls), dfs(tr[u].rs);
}
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;
dfs(x);
}
for (int i = 1; i <= n; i++)
printf("%d", tr[i].color);
return 0;
}