/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 772.0 KiB
#3 Accepted 2ms 548.0 KiB
#4 Accepted 2ms 584.0 KiB
#5 Accepted 56ms 1.117 MiB
#6 Accepted 61ms 1.113 MiB
#7 Accepted 684ms 6.961 MiB
#8 Accepted 744ms 6.953 MiB
#9 Accepted 667ms 6.953 MiB
#10 Accepted 373ms 5.5 MiB

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
Submission
Problem
P1003 Tahsin and Tree
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 20:53:46
Judged At
2024-11-11 03:50:06
Judged By
Score
100
Total Time
744ms
Peak Memory
6.961 MiB