10078 | 2024-03-26 16:27:55 | 111 | Multiplikátoros telebabrátor | cpp17 | Time limit exceeded 20/100 | 598ms | 63428 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 23ms | 2500 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 23ms | 2748 KiB | ||||
4 | Accepted | 23ms | 3128 KiB | ||||
5 | Accepted | 23ms | 3152 KiB | ||||
6 | Accepted | 23ms | 3188 KiB | ||||
7 | Accepted | 23ms | 3340 KiB | ||||
8 | Accepted | 23ms | 3388 KiB | ||||
9 | Accepted | 23ms | 3432 KiB | ||||
10 | Accepted | 23ms | 3600 KiB | ||||
11 | Accepted | 23ms | 4012 KiB | ||||
12 | Accepted | 23ms | 3944 KiB | ||||
13 | Accepted | 23ms | 4128 KiB | ||||
14 | Accepted | 21ms | 4268 KiB | ||||
15 | Accepted | 23ms | 4484 KiB | ||||
16 | Accepted | 23ms | 4480 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Time limit exceeded | 559ms | 14624 KiB | ||||
18 | Time limit exceeded | 583ms | 16784 KiB | ||||
19 | Time limit exceeded | 552ms | 18792 KiB | ||||
20 | Time limit exceeded | 598ms | 20960 KiB | ||||
21 | Time limit exceeded | 575ms | 23388 KiB | ||||
22 | Time limit exceeded | 558ms | 25508 KiB | ||||
23 | Time limit exceeded | 574ms | 27552 KiB | ||||
24 | Time limit exceeded | 572ms | 29824 KiB | ||||
25 | Time limit exceeded | 564ms | 32040 KiB | ||||
26 | Time limit exceeded | 555ms | 34044 KiB | ||||
27 | Time limit exceeded | 552ms | 36184 KiB | ||||
28 | Time limit exceeded | 560ms | 38296 KiB | ||||
29 | Time limit exceeded | 563ms | 40448 KiB | ||||
30 | Time limit exceeded | 560ms | 42776 KiB | ||||
31 | Time limit exceeded | 552ms | 44900 KiB | ||||
32 | Time limit exceeded | 564ms | 47548 KiB | ||||
33 | Time limit exceeded | 573ms | 50508 KiB | ||||
34 | Time limit exceeded | 549ms | 55036 KiB | ||||
35 | Time limit exceeded | 583ms | 53644 KiB | ||||
36 | Time limit exceeded | 569ms | 55524 KiB | ||||
37 | Time limit exceeded | 560ms | 57336 KiB | ||||
38 | Time limit exceeded | 560ms | 59120 KiB | ||||
39 | Time limit exceeded | 532ms | 61192 KiB | ||||
40 | Time limit exceeded | 556ms | 63428 KiB |