100782024-03-26 16:27:55111Multiplikátoros telebabrátorcpp17Time limit exceeded 20/100598ms63428 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("be2.txt","r",stdin);
#endif
	int N;
	cin>>N;
	vector<vector<pair<int,int>>>g(N+1);
	for(int i=0;i<N-1;i++){
		int a,b,c;
		cin>>a>>b>>c;
		g[a].emplace_back(b,c);
		g[b].emplace_back(a,c);
	}
	vector<int>v(N+1);
	auto dfs=[&](auto self,int i,int j)->void{
		for(auto [k,c]:g[j]){
			if(k==i)continue;
			v[k]=v[j]^c;
			self(self,j,k);
		}
	};
	dfs(dfs,0,1);
	vector<int>ans(N+1);
	ans[1]=max_element(v.begin()+1,v.end())-v.begin();
	auto dfs2=[&](auto self,int i,int j)->void{
		for(auto [k,c]:g[j]){
			if(k==i)continue;
			for(int&x:v)x^=c;
			ans[k]=max_element(v.begin()+1,v.end())-v.begin();
			self(self,j,k);
			for(int&x:v)x^=c;
		}
	};
	dfs2(dfs2,0,1);
	for(int i=1;i<=N;i++){
		cout<<ans[i]<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted23ms2500 KiB
subtask220/20
3Accepted23ms2748 KiB
4Accepted23ms3128 KiB
5Accepted23ms3152 KiB
6Accepted23ms3188 KiB
7Accepted23ms3340 KiB
8Accepted23ms3388 KiB
9Accepted23ms3432 KiB
10Accepted23ms3600 KiB
11Accepted23ms4012 KiB
12Accepted23ms3944 KiB
13Accepted23ms4128 KiB
14Accepted21ms4268 KiB
15Accepted23ms4484 KiB
16Accepted23ms4480 KiB
subtask30/80
17Time limit exceeded559ms14624 KiB
18Time limit exceeded583ms16784 KiB
19Time limit exceeded552ms18792 KiB
20Time limit exceeded598ms20960 KiB
21Time limit exceeded575ms23388 KiB
22Time limit exceeded558ms25508 KiB
23Time limit exceeded574ms27552 KiB
24Time limit exceeded572ms29824 KiB
25Time limit exceeded564ms32040 KiB
26Time limit exceeded555ms34044 KiB
27Time limit exceeded552ms36184 KiB
28Time limit exceeded560ms38296 KiB
29Time limit exceeded563ms40448 KiB
30Time limit exceeded560ms42776 KiB
31Time limit exceeded552ms44900 KiB
32Time limit exceeded564ms47548 KiB
33Time limit exceeded573ms50508 KiB
34Time limit exceeded549ms55036 KiB
35Time limit exceeded583ms53644 KiB
36Time limit exceeded569ms55524 KiB
37Time limit exceeded560ms57336 KiB
38Time limit exceeded560ms59120 KiB
39Time limit exceeded532ms61192 KiB
40Time limit exceeded556ms63428 KiB