/ SeriousOJ /

Record Detail

Accepted


  

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=1000000007;
typedef long long ll;
vector<int>edge[M];
int dukba[M];
vector<int>par;
int ot[M];
int bit[M];
int cnt=1;

void dfs(int x,int p){
    dukba[x]=cnt;
    cnt++;
    par.push_back(x);
    for(int u:edge[x]){
        if(u!=p){
            dfs(u,x);
        }
    }
   // cnt++;
    ot[x]=cnt;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    int cas=1;
    while(t--){
     
      int n,q;
      cin>>n>>q;
      vector<int>a(n+2);
      for(int i=1;i<=n;i++)cin>>a[i];
      for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
      }
      cnt=1;
      dfs(1,-1);
      while(q--){
        int node;
        cin>>node;
        int start=dukba[node];
        int finish=ot[node];
        bit[start]+=1;
        bit[finish]-=1;
       
      }
      int sum=0;
      for(int i=0;i<n;i++){
        int x=par[i];
        sum+=bit[i+1];
        if(sum&1){
            if(a[x]==0)a[x]=1;
            else a[x]=0;
        }
      }
      par.clear();
    //  cas++;
      cout<<"Case "<<cas<<": ";
      for(int i=1;i<=n;i++)cout<<a[i]<<" ";
        cout<<"\n";
     for(int i=1;i<=n+1;i++){
        edge[i].clear();
        dukba[i]=0;
        ot[i]=0;
        bit[i]=0;
     }
     cas++;

   }
       

    
    return 0;
 
}

Information

Submit By
Type
Pretest
Problem
P1003 Tahsin and Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-01-05 16:31:13
Judged At
2024-11-11 03:44:12
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes