55622023-07-27 11:20:59zsomborLámpákcpp17Accepted 100/100130ms5716 KiB
#include <iostream>
#include <vector>
using namespace std;

int n, k, q;
vector<int> p(1e5 + 1, 0);
vector<int> d(1e5 + 1, 0);

int binomial(int a, int b){
    if (!b) return 1;
    if (!(a % 2) && b % 2) return 0;
    return binomial(a / 2, b / 2);
}

void query(){
    int a, ans = 0;
    for (int i = 1; i <= n; i++){
        cin >> a;
        if (a) ans += binomial(d[i] + k - 1, d[i]);
    }
    cout << ans % 2 << endl;
}

int main(){
    cin >> n >> k >> q;
    for (int i = 2; i <= n; i++){
        cin >> p[i];
        d[i] = d[p[i]] + 1;
    }
    for (int i = 0; i < q; i++) query();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms3168 KiB
2Accepted3ms3384 KiB
subtask215/15
3Accepted4ms3596 KiB
4Accepted41ms3812 KiB
5Accepted109ms4152 KiB
subtask310/10
6Accepted4ms4232 KiB
7Accepted3ms4292 KiB
8Accepted4ms4388 KiB
9Accepted3ms4292 KiB
10Accepted4ms4416 KiB
subtask430/30
11Accepted43ms4508 KiB
12Accepted48ms4728 KiB
13Accepted46ms4988 KiB
14Accepted48ms5332 KiB
15Accepted52ms5128 KiB
16Accepted43ms5132 KiB
17Accepted50ms5228 KiB
subtask545/45
18Accepted104ms5212 KiB
19Accepted108ms5212 KiB
20Accepted104ms5200 KiB
21Accepted111ms5192 KiB
22Accepted105ms5192 KiB
23Accepted126ms5204 KiB
24Accepted130ms5384 KiB
25Accepted128ms5328 KiB
26Accepted129ms5604 KiB
27Accepted130ms5524 KiB
28Accepted97ms5588 KiB
29Accepted97ms5716 KiB