/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.777 MiB
#2 Accepted 3ms 3.168 MiB
#3 Wrong Answer 3ms 2.824 MiB
#4 Wrong Answer 3ms 2.777 MiB

Code

#include <bits/stdc++.h>
#define pb push_back

using namespace std;

int n,m,a[100005],b[100005],dp[100005];

vector <int> g[100005];

void dfs(int v, int u){
	dp[v] += dp[u];
	if(dp[v] & 1){
		a[v] = 1 - a[v];
	}
	for(auto i : g[v]){
		if(i == u) continue;
		dfs(i,v);
	}
}

int main(){
	
	int tt;
	cin >> tt;
	
	int ind = 0;
	
	while(tt--){
		cin >> n >> m;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}	
	
	for(int i = 1; i < n; i++){
		int x,y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	
	for(int i = 1; i <= m; i++){
		cin >> b[i];
		dp[b[i]]++;
	}

	dfs(1,0);
	
	cout << "Case " << ++ind << ": ";
	
	for(int i = 1; i <= n; i++){
		cout << a[i] << ' ';
		g[i].clear();
		dp[i] = 0;
	}	
	
	}
	
	return 0;
}

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 14:10:56
Judged At
2025-01-02 14:10:56
Judged By
Score
0
Total Time
3ms
Peak Memory
3.168 MiB