1246 | 2022-03-28 22:06:55 | k_balint | Multiplikátoros telebabrátor | cpp14 | Time limit exceeded 20/100 | 598ms | 113208 KiB |
#include <bits/stdc++.h>
using namespace std;
const int c=1e5+5;
const int K=31;
struct edge{
int v,w;
edge(int vv, int ww){
v=vv; w=ww;
}
edge(){
v=w=0;
}
};
struct node{
vector<int> to;
node(){
to.resize(2);
to[0]=to[1]=-1;
}
};
vector<node> trie=vector<node>(1);
void add(int k){
int cur=0;
for(int i=K-1;i>=0;i--){
int j=(k>>i)&1;
if(trie[cur].to[j]==-1){
trie[cur].to[j]=trie.size();
trie.push_back(node());
}
cur=trie[cur].to[j];
}
}
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].to[j^1]!=-1){
res |= 1<<i;
cur=trie[cur].to[j^1];
}
else cur=trie[cur].to[j];
}
return res^k;
}
vector<edge> adj[c];
int d[c];
map<int,int> mp;
void dfs(int v, int p){
mp[d[v]]=v; add(d[v]);
for(edge x:adj[v]){
if(x.v != p){
d[x.v]=d[v]^x.w;
dfs(x.v,v);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin>>n;
for(int i=1;i<n;i++){
int a,b,w; cin>>a>>b>>w;
adj[a].push_back(edge(b,w));
adj[b].push_back(edge(a,w));
}
dfs(1,0);
for(int i=1;i<=n;i++){
cout << mp[maxi(d[i])] << ' ';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6540 KiB | ||||
2 | Accepted | 13ms | 11976 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 13ms | 11912 KiB | ||||
4 | Accepted | 12ms | 11960 KiB | ||||
5 | Accepted | 12ms | 12000 KiB | ||||
6 | Accepted | 13ms | 12036 KiB | ||||
7 | Accepted | 13ms | 12076 KiB | ||||
8 | Accepted | 13ms | 12120 KiB | ||||
9 | Accepted | 13ms | 12160 KiB | ||||
10 | Accepted | 12ms | 12196 KiB | ||||
11 | Accepted | 13ms | 12244 KiB | ||||
12 | Accepted | 13ms | 12296 KiB | ||||
13 | Accepted | 10ms | 12480 KiB | ||||
14 | Accepted | 12ms | 12504 KiB | ||||
15 | Accepted | 12ms | 12544 KiB | ||||
16 | Accepted | 12ms | 12440 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Time limit exceeded | 560ms | 95648 KiB | ||||
18 | Time limit exceeded | 593ms | 97668 KiB | ||||
19 | Time limit exceeded | 517ms | 99748 KiB | ||||
20 | Time limit exceeded | 509ms | 101972 KiB | ||||
21 | Time limit exceeded | 536ms | 104100 KiB | ||||
22 | Time limit exceeded | 536ms | 106164 KiB | ||||
23 | Time limit exceeded | 535ms | 108320 KiB | ||||
24 | Time limit exceeded | 564ms | 110404 KiB | ||||
25 | Time limit exceeded | 552ms | 112480 KiB | ||||
26 | Time limit exceeded | 509ms | 103712 KiB | ||||
27 | Time limit exceeded | 523ms | 98824 KiB | ||||
28 | Time limit exceeded | 531ms | 98784 KiB | ||||
29 | Time limit exceeded | 509ms | 99580 KiB | ||||
30 | Time limit exceeded | 521ms | 101620 KiB | ||||
31 | Time limit exceeded | 518ms | 103880 KiB | ||||
32 | Time limit exceeded | 542ms | 101608 KiB | ||||
33 | Time limit exceeded | 508ms | 101180 KiB | ||||
34 | Time limit exceeded | 514ms | 105120 KiB | ||||
35 | Time limit exceeded | 528ms | 103960 KiB | ||||
36 | Time limit exceeded | 595ms | 106092 KiB | ||||
37 | Time limit exceeded | 595ms | 108060 KiB | ||||
38 | Time limit exceeded | 598ms | 110192 KiB | ||||
39 | Time limit exceeded | 589ms | 112172 KiB | ||||
40 | Time limit exceeded | 577ms | 113208 KiB |