/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.77 MiB
#2 Accepted 3ms 2.77 MiB
#3 Wrong Answer 4ms 2.77 MiB
#4 Wrong Answer 5ms 2.832 MiB

Code

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 100000 + 5;
int tc, n, casee = 1, q, tm = 0, a[N], start[N], finish[N], cnt[N];
vector<int> adj[N];

void dfs(int u, int par) {
    start[u] = ++tm;
    for (int v : adj[u]) {
        if (v == par)
            continue;
        dfs(v, u);
    }
    finish[u] = tm;
}

int main() {
    cin >> tc;
    while (tc--) {
        cin >> n >> q;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        for (int i = 1; i <= n - 1; i++) {
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        dfs(1, 0);

        while (q--) {
            int node;
            cin >> node;
            cnt[start[node]]++;
            cnt[finish[node] + 1]--;
        }

        for (int i = 1; i <= n; i++) {
            cnt[i] += cnt[i - 1];
        }

        cout << "Case " << casee++ << ": ";

        for (int i = 1; i <= n; i++) {
            int val = a[i];
            if (cnt[start[i]] % 2 == 0) {
                cout << val << " ";
            } else {
                cout << !val << " ";
            }
        }

        cout << endl;

        for (int i = 1; i <= n; i++) {
            adj[i].clear();
            start[i] = finish[i] = cnt[i] = 0;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Contest
Beta Round #1
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 16:29:52
Judged At
2024-11-11 03:51:01
Judged By
Score
0
Total Time
5ms
Peak Memory
2.832 MiB