/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Wrong Answer 2ms 532.0 KiB
#4 Wrong Answer 2ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

void dfs(int node,int t,int parent,vector<int>&tgl,vector<vector<int>>&tree,vector<int>&a)
{
    //if(node==parent) return;
    t += tgl[node];
    if(t%2) a[node] ^=1;

    for(auto e:tree[node])
    {
        if(e==parent) continue;
        dfs(e,t,node,tgl,tree,a);
    }
}

void solve(int tc)
{
    int n,q; cin>>n>>q;
    vector<vector<int>> tree(n+1);
    vector<int>a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    int u,v;
    
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    vector<int>tgl(n+1);
    while(q--)
    {
        cin>>u;
        tgl[u]++;
    }

    dfs(1,0,0,tgl,tree,a);
    cout<<"Case "<<tc<<": ";
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
    cout<<endl;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t; cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }}

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-02-15 19:33:52
Judged At
2024-11-11 03:43:11
Judged By
Score
0
Total Time
2ms
Peak Memory
532.0 KiB