#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
ll dfs(ll vertex, vector<bool> &states, const vector<vector<ll>> &tree) {
bool si;
ll signals;
signals = 0;
for(const auto &x : tree[vertex])
signals += dfs(x, states, tree);
si = states[vertex];
states[vertex] = (states[vertex] + signals) % 2;
if(si)
signals++;
return signals;
}
int main() {
FastIO;
ll i, u, s, N, K, Q;
cin >> N >> K >> Q;
vector<vector<ll>> tree(N);
for(i = 1; i < N; i++) {
cin >> u;
tree[u - 1].push_back(i);
}
vector<bool> states(N);
while(Q--) {
for(i = 0; i < N; i++) {
cin >> s;
states[i] = s;
}
for(i = 0; i < K; i++)
dfs(0, states, tree);
cout << states[0] << '\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1972 KiB | ||||
2 | Accepted | 3ms | 2108 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Time limit exceeded | 1.1s | 1516 KiB | ||||
4 | Time limit exceeded | 1.07s | 2104 KiB | ||||
5 | Time limit exceeded | 1.065s | 5088 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 17ms | 2568 KiB | ||||
7 | Accepted | 19ms | 2780 KiB | ||||
8 | Accepted | 14ms | 2992 KiB | ||||
9 | Accepted | 12ms | 3076 KiB | ||||
10 | Accepted | 8ms | 3076 KiB | ||||
subtask4 | 0/30 | ||||||
11 | Time limit exceeded | 1.065s | 2320 KiB | ||||
12 | Time limit exceeded | 1.069s | 3052 KiB | ||||
13 | Time limit exceeded | 1.077s | 2440 KiB | ||||
14 | Time limit exceeded | 1.057s | 3044 KiB | ||||
15 | Time limit exceeded | 1.054s | 2336 KiB | ||||
16 | Time limit exceeded | 1.069s | 3328 KiB | ||||
17 | Time limit exceeded | 1.046s | 2536 KiB | ||||
subtask5 | 0/45 | ||||||
18 | Time limit exceeded | 1.07s | 3724 KiB | ||||
19 | Time limit exceeded | 1.054s | 4168 KiB | ||||
20 | Time limit exceeded | 1.065s | 4360 KiB | ||||
21 | Time limit exceeded | 1.057s | 5692 KiB | ||||
22 | Time limit exceeded | 1.062s | 5720 KiB | ||||
23 | Time limit exceeded | 1.062s | 6904 KiB | ||||
24 | Time limit exceeded | 1.077s | 9172 KiB | ||||
25 | Time limit exceeded | 1.057s | 9316 KiB | ||||
26 | Time limit exceeded | 1.077s | 14668 KiB | ||||
27 | Time limit exceeded | 1.062s | 14556 KiB | ||||
28 | Time limit exceeded | 1.07s | 3032 KiB | ||||
29 | Time limit exceeded | 1.042s | 3100 KiB |