/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 5ms 5.57 MiB
#2 Wrong Answer 4ms 6.473 MiB

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 bit[M];
int cnt=1;
int query(int id){
    int sum=0;
    while(id>0){
         sum+=bit[id];
         id-=id&(-id);
    }
    return sum;
}
void upade(int id,int val,int n){
           while(id<=n){
            bit[id]+=val;
            id+=id&(-id);
           }
}
void dfs(int x,int p){
    dukba[x]=cnt;
    par.push_back(x);
    for(int u:edge[x]){
        if(u!=p){
            dfs(u,x);
        }
    }
    cnt++;
    //out[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;
        upade(dukba[node],1,n);
      }
      for(int i=0;i<n;i++){
        int x=par[i];
        int c=query(dukba[x])-query(dukba[x]-1);
        if(c&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<<a[n];
        cout<<"\n";
     for(int i=1;i<=n;i++){
        edge[i].clear();
        dukba[i]=0;
        //out[i]=0;
        bit[i]=0;
     }
     cas++;

   }
       

    
    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 17:51:44
Judged At
2024-11-11 03:50:23
Judged By
Score
0
Total Time
5ms
Peak Memory
6.473 MiB