/ SeriousOJ /

Record Detail

Accepted


  

Code

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

int main()
{
	// fio();

	int t,cs=0; cin>>t;
	while(t--){
		int n,q; cin>>n>>q;
		bool a[n+1]={};
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		
		vector<int>g[n+1];
		for(int i=0;i<n-1;i++){
			int u,v; cin>>u>>v;
			g[u].push_back(v); g[v].push_back(u);
		}

		bool c[n+1] = {};
		for(int i=0;i<q;i++){
			int x; cin>>x;
			c[x]^=1;
		}
		
		function<void(int,int)>f=[&](int s, int p)
		{
			if(p!=-1) c[s]^=c[p];
			for(auto to:g[s]){
				if(to^p){
					f(to,s);
				}
			}
		};

		f(1,-1);
		
		cout<<"Case "<<++cs<<":";
		for(int i=1;i<=n;i++){
			cout<<' '<<(a[i]^c[i]);
		} cout<<endl;
	}
    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1003 Tahsin and Tree
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 20:53:43
Judged At
2024-11-11 03:50:07
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes