#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> d;
void dfs(int n, int dep)
{
d[n] = dep;
for(auto x : g[n]) dfs(x, dep + 1);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, q;
cin >> n >> k >> q;
g.resize(n + 1);
d.resize(n + 1);
for(int i = 2; i <= n; i++)
{
int x;
cin >> x;
g[x].push_back(i);
}
dfs(1, 0);
while(q--)
{
int ans = 0;
for(int i = 1; i <= n; i++)
{
int x;
cin >> x;
if(((d[i] + k - 1) & (k - 1)) == (k - 1)) ans ^= x;
}
cout << ans << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1764 KiB | ||||
2 | Accepted | 3ms | 1920 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 3ms | 2148 KiB | ||||
4 | Accepted | 18ms | 3092 KiB | ||||
5 | Accepted | 50ms | 9248 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 2656 KiB | ||||
7 | Accepted | 3ms | 2868 KiB | ||||
8 | Accepted | 3ms | 2880 KiB | ||||
9 | Accepted | 3ms | 3128 KiB | ||||
10 | Accepted | 3ms | 3232 KiB | ||||
subtask4 | 30/30 | ||||||
11 | Accepted | 14ms | 3428 KiB | ||||
12 | Accepted | 14ms | 3776 KiB | ||||
13 | Accepted | 14ms | 3736 KiB | ||||
14 | Accepted | 14ms | 3936 KiB | ||||
15 | Accepted | 14ms | 3944 KiB | ||||
16 | Accepted | 14ms | 3940 KiB | ||||
17 | Accepted | 14ms | 3940 KiB | ||||
subtask5 | 45/45 | ||||||
18 | Accepted | 46ms | 6020 KiB | ||||
19 | Accepted | 46ms | 6476 KiB | ||||
20 | Accepted | 46ms | 6468 KiB | ||||
21 | Accepted | 46ms | 8268 KiB | ||||
22 | Accepted | 46ms | 8168 KiB | ||||
23 | Accepted | 64ms | 12928 KiB | ||||
24 | Accepted | 61ms | 15088 KiB | ||||
25 | Accepted | 61ms | 15092 KiB | ||||
26 | Accepted | 63ms | 20956 KiB | ||||
27 | Accepted | 63ms | 21104 KiB | ||||
28 | Accepted | 39ms | 4972 KiB | ||||
29 | Accepted | 39ms | 4944 KiB |