1 条题解
-
0
#include <iostream>
using namespace std; long long n, h[5000010], w[5000010], fa[5000000], ans, cnt, head[5000010], to[5000010], nxt[5000010]; char s[5000010]; void dfs(long long x){ w[x] = w[fa[x]]; if(s[x] == '(') w[x] = x; else if(w[x]){ h[x] = 1 + h[fa[w[x]]]; w[x] = w[fa[w[x]]]; } for(int i = head[x]; i; i = nxt[i]) dfs(to[i]); } int main(){ cin >> n; cin >> (s + 1); long long x; for(long long i = 2;i <= n;i++){ cin >> x; fa[i] = x; cnt++; nxt[cnt] = head[x]; head[x] = cnt; to[cnt] = i; } dfs(1); ans = h[1]; for(long long i = 2;i <= n;i++){ h[i] += h[fa[i]]; ans ^= (i * h[i]); } cout << ans << endl; }
- 1
信息
- ID
- 454
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 4
- 已通过
- 3
- 上传者