/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 12.637 MiB
#2 Wrong Answer 7ms 11.648 MiB
#3 Wrong Answer 39ms 13.816 MiB

Code

/**
 *  written by Binoy Barman .
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "debug/whereisit.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

const int N = 2e5 + 9;

int n, preCleared = 1;
int a[N], on[N], off[N], lazy[N], lvl[N], par[N];
vector<int> g[N];

inline void push(int k) {
    if(lazy[k] == 0) {
        return;
    }
    if(lazy[k] & 1) swap(on[k], off[k]);
    for(auto u : g[k]) {
        lazy[u] += lazy[k];
    }
    lazy[k] = 0;
}
pair<int, int> dfs(int v, int p = -1) {
    lazy[v] = 0;
    par[v] = p;
    for(auto u : g[v]) {
        if(u == p) continue;
        lvl[u] = lvl[v] + 1;
        auto tmp = dfs(u, v);
        on[v] += tmp.first;
        off[v] += tmp.second;
    }
    on[v] += a[v] == 1;
    off[v] += a[v] == 0;
    return {on[v], off[v]};
}
void toggle(int k, int v, int p = -1) {
    push(v);
    if(v == k) {
        return;
    }
    for(auto u : g[v]) {
        if(u == p) continue;
        toggle(k, u, v);
    }
}

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        on[i] = off[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    int q;
    cin >> q;
    while(q--) {
        int t, k;
        cin >> t >> k;
        if(t == 1) {
            lazy[k]++;
            if(lvl[k] < lvl[preCleared]) toggle(k, k, par[k]);
            else toggle(k, preCleared, par[preCleared]);
            preCleared = k;
        } else {
            if(lvl[k] < lvl[preCleared]) toggle(k, k, par[k]);
            else toggle(k, preCleared, par[preCleared]);
            preCleared = k;
            cout << on[k] << nl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1101 Mr. Heart and the Enchanted Lights
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 18:28:30
Judged At
2024-11-11 02:45:09
Judged By
Score
5
Total Time
39ms
Peak Memory
13.816 MiB