/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 4ms 2.742 MiB
#2 Wrong Answer 3ms 2.77 MiB

Code

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

using namespace std;

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

void dfs(int u, int par) {
    start[u] = ++tm;
    revIdx[++idx] = u;

    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);
        }

        tm = idx = 0;

        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 originalValue = a[i];
            int cntSum = cnt[revIdx[i]];
            if (cntSum % 2 == 0) {
                cout << originalValue << " ";
            } else {
                cout << !originalValue << " ";
            }
        }

        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:45:46
Judged At
2024-11-11 03:50:51
Judged By
Score
0
Total Time
4ms
Peak Memory
2.77 MiB