#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
bool is_binomial_odd(ll n, ll k) {
if(!k)
return true;
if((1 - n & 1) && (k & 1))
return false;
return is_binomial_odd(n / 2, k / 2);
}
int main() {
FastIO;
ll i, ans, N, K, Q, P, S;
cin >> N >> K >> Q;
vector<ll> D(N + 1);
D[1] = 0;
for(i = 2; i <= N; i++) {
cin >> P;
D[i] = D[P] + 1;
}
while(Q--) {
cin >> ans;
for(i = 2; i <= N; i++) {
cin >> S;
if(S && is_binomial_odd(D[i] + K - 1, D[i]))
ans ^= 1;
}
cout << ans << '\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 3ms | 2240 KiB | ||||
4 | Accepted | 19ms | 2680 KiB | ||||
5 | Accepted | 52ms | 4184 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 2832 KiB | ||||
7 | Accepted | 3ms | 2924 KiB | ||||
8 | Accepted | 3ms | 2932 KiB | ||||
9 | Accepted | 3ms | 3160 KiB | ||||
10 | Accepted | 3ms | 3384 KiB | ||||
subtask4 | 30/30 | ||||||
11 | Accepted | 16ms | 3516 KiB | ||||
12 | Accepted | 16ms | 3496 KiB | ||||
13 | Accepted | 16ms | 3696 KiB | ||||
14 | Accepted | 16ms | 3832 KiB | ||||
15 | Accepted | 14ms | 4040 KiB | ||||
16 | Accepted | 16ms | 4256 KiB | ||||
17 | Accepted | 14ms | 4332 KiB | ||||
subtask5 | 45/45 | ||||||
18 | Accepted | 48ms | 4584 KiB | ||||
19 | Accepted | 52ms | 4516 KiB | ||||
20 | Accepted | 48ms | 4500 KiB | ||||
21 | Accepted | 52ms | 4496 KiB | ||||
22 | Accepted | 50ms | 4772 KiB | ||||
23 | Accepted | 57ms | 5936 KiB | ||||
24 | Accepted | 59ms | 5992 KiB | ||||
25 | Accepted | 57ms | 6000 KiB | ||||
26 | Accepted | 57ms | 6000 KiB | ||||
27 | Accepted | 59ms | 6012 KiB | ||||
28 | Accepted | 45ms | 4660 KiB | ||||
29 | Accepted | 45ms | 4652 KiB |