#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define ll long long
int fa[N],pre[N];
ll f[N];
string str;
bool vis[N] = {1,1},ok[N] = {1};
ll F(int x)
{
if(vis[x]) return f[x];
vis[x] = 1;
f[x] = F(fa[x]);
if(str[x] == ')' && pre[x]) ++f[x];
return f[x];
}
int find(int x)
{
if(ok[x]) return pre[x];
ok[x] = 1;
if(str[fa[x]] == '(') return pre[x] = fa[x];
if(str[x] == '(') return pre[x] = find(fa[x]);
return pre[x] = find(find(fa[x]));
}
inline int read()
{
int x = 0,f = 1;
char c = getchar();
while(!isdigit(c)) { if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) { x = (x<<1) + (x<<3) + c-'0'; c = getchar();}
return x*f;
}
int main()
{
int n = read();
cin >> str;
str = "0" + str;
for(int i = 2;i <= n;++ i)
fa[i] = read();
ll ans = 0;
for(int i = 1;i <= n;++ i) find(i);
for(int i = 1;i <= n;++ i)
{
ans ^= (i*F(i));
printf("%d ",f[i]);
}
printf("%lld\n",ans);
return 0;
}
只得了10分,其它全WA,是思路有问题吧??