/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 412.0 KiB
#2 Accepted 1ms 328.0 KiB
#3 Accepted 1ms 344.0 KiB
#4 Accepted 1ms 412.0 KiB
#5 Accepted 29ms 1.133 MiB
#6 Accepted 35ms 1.047 MiB
#7 Accepted 678ms 7.59 MiB
#8 Accepted 311ms 7.598 MiB
#9 Accepted 285ms 7.586 MiB
#10 Accepted 137ms 5.934 MiB

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++) 
    {
        if(i==n) cout<<a[i];
        else 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-16 04:19:52
Judged At
2024-03-04 15:04:53
Judged By
Score
100
Total Time
678ms
Peak Memory
7.598 MiB