5094 | 2023-04-16 16:25:26 | szil | Multiplikátoros telebabrátor | cpp14 | Wrong answer 0/100 | 333ms | 125296 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 = 31; 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 = 31; 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 | 11196 KiB | ||||
2 | Accepted | 9ms | 14212 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Wrong answer | 9ms | 14424 KiB | ||||
4 | Accepted | 9ms | 14728 KiB | ||||
5 | Wrong answer | 10ms | 14768 KiB | ||||
6 | Accepted | 9ms | 14972 KiB | ||||
7 | Wrong answer | 9ms | 15284 KiB | ||||
8 | Wrong answer | 9ms | 15144 KiB | ||||
9 | Accepted | 9ms | 15396 KiB | ||||
10 | Accepted | 9ms | 15604 KiB | ||||
11 | Accepted | 9ms | 15928 KiB | ||||
12 | Wrong answer | 10ms | 16148 KiB | ||||
13 | Accepted | 10ms | 16492 KiB | ||||
14 | Wrong answer | 9ms | 16732 KiB | ||||
15 | Wrong answer | 9ms | 16736 KiB | ||||
16 | Wrong answer | 8ms | 16712 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Wrong answer | 312ms | 113092 KiB | ||||
18 | Accepted | 256ms | 113060 KiB | ||||
19 | Wrong answer | 254ms | 112904 KiB | ||||
20 | Accepted | 252ms | 112928 KiB | ||||
21 | Accepted | 312ms | 112988 KiB | ||||
22 | Wrong answer | 310ms | 112976 KiB | ||||
23 | Accepted | 310ms | 113012 KiB | ||||
24 | Accepted | 256ms | 113032 KiB | ||||
25 | Wrong answer | 256ms | 112980 KiB | ||||
26 | Wrong answer | 307ms | 113256 KiB | ||||
27 | Accepted | 256ms | 113284 KiB | ||||
28 | Accepted | 252ms | 113132 KiB | ||||
29 | Wrong answer | 263ms | 112652 KiB | ||||
30 | Wrong answer | 312ms | 113012 KiB | ||||
31 | Accepted | 314ms | 113268 KiB | ||||
32 | Accepted | 319ms | 115688 KiB | ||||
33 | Accepted | 324ms | 118172 KiB | ||||
34 | Accepted | 326ms | 125296 KiB | ||||
35 | Wrong answer | 254ms | 114444 KiB | ||||
36 | Accepted | 245ms | 114260 KiB | ||||
37 | Accepted | 241ms | 113980 KiB | ||||
38 | Accepted | 296ms | 113880 KiB | ||||
39 | Wrong answer | 291ms | 113720 KiB | ||||
40 | Wrong answer | 333ms | 113072 KiB |