5093 | 2023-04-16 16:23:39 | szil | Multiplikátoros telebabrátor | cpp14 | Wrong answer 0/100 | 358ms | 125212 KiB |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int MAXN = 200001;
vector<pair<int, int>> g[MAXN];
int d[MAXN];
struct Node {
Node *a[2];
int u = -1;
Node() {
a[0] = a[1] = nullptr;
}
};
Node *root;
void add(int u) {
Node *cur = root;
for (int i = 29; i >= 0; i--) {
int x = (d[u] >> i) & 1;
if (cur->a[x] == nullptr) cur->a[x] = new Node();
cur = cur->a[x];
}
cur->u = u;
}
void dfs(int u, int p = 0) {
for (auto [v, w] : g[u]) {
if (v != p) {
d[v] = d[u] ^ w;
add(v);
dfs(v, u);
}
}
}
void solve() {
root = new Node();
int n; cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b, w; cin >> a >> b >> w;
g[a].push_back({b, w});
g[b].push_back({a, w});
}
dfs(1);
for (int i = 1; i <= n; i++) {
Node *cur = root;
for (int j = 29; j >= 0; j--) {
int x = (d[i] >> j) & 1;
if (cur->a[!x] != nullptr) cur = cur->a[!x];
else cur = cur->a[x];
}
cout << cur->u << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 7ms | 11320 KiB | ||||
2 | Accepted | 10ms | 14336 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Wrong answer | 9ms | 14480 KiB | ||||
4 | Accepted | 10ms | 14432 KiB | ||||
5 | Wrong answer | 10ms | 14428 KiB | ||||
6 | Accepted | 9ms | 14688 KiB | ||||
7 | Wrong answer | 10ms | 14884 KiB | ||||
8 | Wrong answer | 9ms | 15112 KiB | ||||
9 | Accepted | 9ms | 15216 KiB | ||||
10 | Accepted | 9ms | 15168 KiB | ||||
11 | Accepted | 9ms | 15184 KiB | ||||
12 | Wrong answer | 9ms | 15456 KiB | ||||
13 | Accepted | 9ms | 15600 KiB | ||||
14 | Wrong answer | 9ms | 15656 KiB | ||||
15 | Wrong answer | 9ms | 15620 KiB | ||||
16 | Wrong answer | 9ms | 15592 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Wrong answer | 254ms | 111960 KiB | ||||
18 | Accepted | 312ms | 112464 KiB | ||||
19 | Wrong answer | 330ms | 112412 KiB | ||||
20 | Accepted | 314ms | 112636 KiB | ||||
21 | Accepted | 319ms | 112624 KiB | ||||
22 | Wrong answer | 261ms | 112612 KiB | ||||
23 | Accepted | 259ms | 112648 KiB | ||||
24 | Accepted | 256ms | 112896 KiB | ||||
25 | Wrong answer | 317ms | 113036 KiB | ||||
26 | Wrong answer | 298ms | 113476 KiB | ||||
27 | Accepted | 275ms | 113268 KiB | ||||
28 | Accepted | 358ms | 113256 KiB | ||||
29 | Wrong answer | 314ms | 112788 KiB | ||||
30 | Wrong answer | 270ms | 112924 KiB | ||||
31 | Accepted | 316ms | 113320 KiB | ||||
32 | Accepted | 263ms | 115612 KiB | ||||
33 | Accepted | 263ms | 118088 KiB | ||||
34 | Accepted | 263ms | 125212 KiB | ||||
35 | Wrong answer | 298ms | 114484 KiB | ||||
36 | Accepted | 239ms | 114304 KiB | ||||
37 | Accepted | 238ms | 114052 KiB | ||||
38 | Accepted | 291ms | 113920 KiB | ||||
39 | Wrong answer | 237ms | 113772 KiB | ||||
40 | Wrong answer | 231ms | 113180 KiB |