1248 | 2022-03-28 22:13:55 | k_balint | Multiplikátoros telebabrátor | cpp14 | Time limit exceeded 20/100 | 596ms | 128432 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.emplace_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];
vector<pair<int,int>> mp;
void dfs(int v, int p){
mp.emplace_back(make_pair(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);
sort(mp.begin(),mp.end());
for(int i=1;i<=n;i++){
int cur=maxi(d[i]);
auto it=lower_bound(mp.begin(),mp.end(),make_pair(cur,-1));
cout << it->second << ' ';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6564 KiB | ||||
2 | Accepted | 13ms | 11900 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 10ms | 11872 KiB | ||||
4 | Accepted | 12ms | 11892 KiB | ||||
5 | Accepted | 10ms | 11988 KiB | ||||
6 | Accepted | 10ms | 12060 KiB | ||||
7 | Accepted | 12ms | 12056 KiB | ||||
8 | Accepted | 12ms | 12156 KiB | ||||
9 | Accepted | 12ms | 12124 KiB | ||||
10 | Accepted | 10ms | 12192 KiB | ||||
11 | Accepted | 12ms | 12212 KiB | ||||
12 | Accepted | 12ms | 12296 KiB | ||||
13 | Accepted | 12ms | 12412 KiB | ||||
14 | Accepted | 12ms | 12372 KiB | ||||
15 | Accepted | 12ms | 12448 KiB | ||||
16 | Accepted | 10ms | 12436 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Time limit exceeded | 569ms | 91492 KiB | ||||
18 | Time limit exceeded | 560ms | 93588 KiB | ||||
19 | Time limit exceeded | 513ms | 95724 KiB | ||||
20 | Time limit exceeded | 584ms | 97824 KiB | ||||
21 | Time limit exceeded | 578ms | 100028 KiB | ||||
22 | Time limit exceeded | 589ms | 102060 KiB | ||||
23 | Time limit exceeded | 538ms | 104180 KiB | ||||
24 | Time limit exceeded | 505ms | 106300 KiB | ||||
25 | Time limit exceeded | 577ms | 108528 KiB | ||||
26 | Time limit exceeded | 591ms | 110708 KiB | ||||
27 | Time limit exceeded | 593ms | 112892 KiB | ||||
28 | Time limit exceeded | 569ms | 114896 KiB | ||||
29 | Time limit exceeded | 582ms | 116732 KiB | ||||
30 | Time limit exceeded | 583ms | 118980 KiB | ||||
31 | Time limit exceeded | 588ms | 121184 KiB | ||||
32 | Time limit exceeded | 563ms | 124444 KiB | ||||
33 | Time limit exceeded | 566ms | 122440 KiB | ||||
34 | Time limit exceeded | 593ms | 124436 KiB | ||||
35 | Time limit exceeded | 595ms | 122168 KiB | ||||
36 | Time limit exceeded | 596ms | 124420 KiB | ||||
37 | Time limit exceeded | 591ms | 126336 KiB | ||||
38 | Time limit exceeded | 574ms | 128400 KiB | ||||
39 | Time limit exceeded | 588ms | 128432 KiB | ||||
40 | Time limit exceeded | 584ms | 123580 KiB |