55482023-07-22 23:43:22gortomiLámpákcpp17Accepted 100/10064ms21104 KiB
#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";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1764 KiB
2Accepted3ms1920 KiB
subtask215/15
3Accepted3ms2148 KiB
4Accepted18ms3092 KiB
5Accepted50ms9248 KiB
subtask310/10
6Accepted3ms2656 KiB
7Accepted3ms2868 KiB
8Accepted3ms2880 KiB
9Accepted3ms3128 KiB
10Accepted3ms3232 KiB
subtask430/30
11Accepted14ms3428 KiB
12Accepted14ms3776 KiB
13Accepted14ms3736 KiB
14Accepted14ms3936 KiB
15Accepted14ms3944 KiB
16Accepted14ms3940 KiB
17Accepted14ms3940 KiB
subtask545/45
18Accepted46ms6020 KiB
19Accepted46ms6476 KiB
20Accepted46ms6468 KiB
21Accepted46ms8268 KiB
22Accepted46ms8168 KiB
23Accepted64ms12928 KiB
24Accepted61ms15088 KiB
25Accepted61ms15092 KiB
26Accepted63ms20956 KiB
27Accepted63ms21104 KiB
28Accepted39ms4972 KiB
29Accepted39ms4944 KiB