#include <bits/stdc++.h> using namespace std;
typedef long long ll; const int maxn = 1e5+10;
int n,tot; int id[maxn<<1],cnt,node[maxn],d[maxn<<1],h[maxn]; int fir[maxn]; string s;
struct BinaryTreeNode{ int fa; int data; int LChild,RChild; }tree[maxn];
inline void read(int &x){ x = 0; char c = 0; int w = 0; while(!isdigit(c)){ w |= c == '-'; c = getchar(); } while(isdigit(c)){ x = x*10+c-'0'; c = getchar(); } if(w) x = -x; }
void dfs(int idx){ id[++cnt] = idx; fir[idx] = cnt; int e = cnt; if(tree[idx].LChild != 0) dfs(tree[idx].LChild); if(tree[idx].RChild != 0) dfs(tree[idx].RChild); id[++cnt] = idx; node[idx] = cnt-e; }
int main(){ read(n); tree[1].fa = 0; for(int i=2;i<=n;i++){ int f; read(f); tree[i].fa = f; if(tree[f].LChild == 0) tree[f].LChild = i; else tree[f].RChild = i; } cin>>s; for(int i=0;i<s.size();i++) tree[i+1].data = s[i]-'0'; dfs(1); int q; read(q); while(q--){ int cur; read(cur); int l = fir[cur]; int r = l+node[cur]; d[l] ++; d[r+1] --; } int sum = 0; for(int i=1;i<=cnt;i++){ sum += d[i]; if(sum%2 == 1 && !h[id[i]]) tree[id[i]].data = !tree[id[i]].data; h[id[i]]++; } for(int i=1;i<=n;i++) printf("%d",tree[i].data); return 0; }
共 2 条回复
@root ok!
洛谷 A 了,那我估计是数据的锅,这个数据是网上的,回头我再修一下