1251 | 2022-03-28 22:34:48 | k_balint | Multiplikátoros telebabrátor | cpp14 | Accepted 100/100 | 421ms | 98588 KiB |
#include <bits/stdc++.h>
using namespace std;
const int c=1e5+5;
const int K=30;
struct edge{
int v,w;
edge(int vv, int ww){
v=vv; w=ww;
}
edge(){
v=w=0;
}
};
int trie[31*c][2];
int sz=1;
inline void add(int k){
int cur=0;
for(int i=K-1;i>=0;i--){
int j=(k>>i)&1;
if(!trie[cur][j]){
trie[cur][j]=sz++;
}
cur=trie[cur][j];
}
}
inline int maxi(int k){
int res=0; int cur=0;
for(int i=K-1;i>=0;i--){
int j=(k>>i)&1;
if(trie[cur][j^1]!=0){
res |= 1<<i;
cur=trie[cur][j^1];
}
else cur=trie[cur][j];
}
return res^k;
}
vector<edge> adj[c];
int d[c];
map<int,int> mp;
void dfs(int v, int p){
for(edge x:adj[v]){
if(x.v != p){
d[x.v]=d[v]^x.w;
dfs(x.v,v);
}
}
}
inline int read(){
int res=0; char ch=getchar();
while(!isdigit(ch)){
ch=getchar();
}
while(isdigit(ch)){
res=(res<<3)+(res<<1)+ch-'0';
ch=getchar();
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n=read();
for(int i=1;i<n;i++){
int a,b,w; a=read(); b=read(); w=read();
adj[a].emplace_back(edge(b,w));
adj[b].emplace_back(edge(a,w));
}
dfs(1,0);
for(int i=1;i<=n;i++){
mp[d[i]]=i;
add(d[i]);
}
for(int i=1;i<=n;i++){
int cur=maxi(d[i]);
cout << mp[cur] << ' ';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6600 KiB | ||||
2 | Accepted | 6ms | 7660 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 6ms | 7636 KiB | ||||
4 | Accepted | 7ms | 7676 KiB | ||||
5 | Accepted | 6ms | 7724 KiB | ||||
6 | Accepted | 7ms | 7760 KiB | ||||
7 | Accepted | 8ms | 7800 KiB | ||||
8 | Accepted | 8ms | 7848 KiB | ||||
9 | Accepted | 6ms | 7880 KiB | ||||
10 | Accepted | 6ms | 7928 KiB | ||||
11 | Accepted | 6ms | 7972 KiB | ||||
12 | Accepted | 6ms | 8148 KiB | ||||
13 | Accepted | 6ms | 8236 KiB | ||||
14 | Accepted | 6ms | 8228 KiB | ||||
15 | Accepted | 6ms | 8136 KiB | ||||
16 | Accepted | 6ms | 8164 KiB | ||||
subtask3 | 80/80 | ||||||
17 | Accepted | 368ms | 49732 KiB | ||||
18 | Accepted | 275ms | 51836 KiB | ||||
19 | Accepted | 277ms | 53972 KiB | ||||
20 | Accepted | 298ms | 56108 KiB | ||||
21 | Accepted | 296ms | 58228 KiB | ||||
22 | Accepted | 291ms | 60352 KiB | ||||
23 | Accepted | 335ms | 62472 KiB | ||||
24 | Accepted | 286ms | 64584 KiB | ||||
25 | Accepted | 291ms | 66604 KiB | ||||
26 | Accepted | 286ms | 69036 KiB | ||||
27 | Accepted | 305ms | 71148 KiB | ||||
28 | Accepted | 282ms | 73268 KiB | ||||
29 | Accepted | 284ms | 75012 KiB | ||||
30 | Accepted | 421ms | 77140 KiB | ||||
31 | Accepted | 314ms | 79476 KiB | ||||
32 | Accepted | 300ms | 83464 KiB | ||||
33 | Accepted | 349ms | 87584 KiB | ||||
34 | Accepted | 331ms | 95100 KiB | ||||
35 | Accepted | 308ms | 88988 KiB | ||||
36 | Accepted | 287ms | 90944 KiB | ||||
37 | Accepted | 287ms | 92668 KiB | ||||
38 | Accepted | 275ms | 94836 KiB | ||||
39 | Accepted | 272ms | 96704 KiB | ||||
40 | Accepted | 310ms | 98588 KiB |