76742024-01-10 12:18:10anonLámpákcpp17Time limit exceeded 10/1001.1s14668 KiB
#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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1972 KiB
2Accepted3ms2108 KiB
subtask20/15
3Time limit exceeded1.1s1516 KiB
4Time limit exceeded1.07s2104 KiB
5Time limit exceeded1.065s5088 KiB
subtask310/10
6Accepted17ms2568 KiB
7Accepted19ms2780 KiB
8Accepted14ms2992 KiB
9Accepted12ms3076 KiB
10Accepted8ms3076 KiB
subtask40/30
11Time limit exceeded1.065s2320 KiB
12Time limit exceeded1.069s3052 KiB
13Time limit exceeded1.077s2440 KiB
14Time limit exceeded1.057s3044 KiB
15Time limit exceeded1.054s2336 KiB
16Time limit exceeded1.069s3328 KiB
17Time limit exceeded1.046s2536 KiB
subtask50/45
18Time limit exceeded1.07s3724 KiB
19Time limit exceeded1.054s4168 KiB
20Time limit exceeded1.065s4360 KiB
21Time limit exceeded1.057s5692 KiB
22Time limit exceeded1.062s5720 KiB
23Time limit exceeded1.062s6904 KiB
24Time limit exceeded1.077s9172 KiB
25Time limit exceeded1.057s9316 KiB
26Time limit exceeded1.077s14668 KiB
27Time limit exceeded1.062s14556 KiB
28Time limit exceeded1.07s3032 KiB
29Time limit exceeded1.042s3100 KiB