5092 | 2023-04-16 16:21:30 | szil | Multiplikátoros telebabrátor | cpp14 | Wrong answer 0/100 | 331ms | 125032 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 = 30; 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 = 30; 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 | 11188 KiB | ||||
2 | Accepted | 9ms | 14144 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Wrong answer | 9ms | 14364 KiB | ||||
4 | Accepted | 10ms | 14564 KiB | ||||
5 | Wrong answer | 10ms | 14776 KiB | ||||
6 | Accepted | 10ms | 15096 KiB | ||||
7 | Wrong answer | 9ms | 15308 KiB | ||||
8 | Wrong answer | 9ms | 15524 KiB | ||||
9 | Accepted | 9ms | 15728 KiB | ||||
10 | Accepted | 9ms | 15584 KiB | ||||
11 | Accepted | 10ms | 15904 KiB | ||||
12 | Wrong answer | 9ms | 15960 KiB | ||||
13 | Accepted | 9ms | 16152 KiB | ||||
14 | Wrong answer | 9ms | 15908 KiB | ||||
15 | Wrong answer | 9ms | 15904 KiB | ||||
16 | Wrong answer | 8ms | 15884 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Wrong answer | 254ms | 112264 KiB | ||||
18 | Accepted | 254ms | 112236 KiB | ||||
19 | Wrong answer | 254ms | 112264 KiB | ||||
20 | Accepted | 254ms | 112288 KiB | ||||
21 | Accepted | 256ms | 112268 KiB | ||||
22 | Wrong answer | 254ms | 112560 KiB | ||||
23 | Accepted | 256ms | 112504 KiB | ||||
24 | Accepted | 254ms | 112476 KiB | ||||
25 | Wrong answer | 256ms | 112372 KiB | ||||
26 | Wrong answer | 252ms | 112684 KiB | ||||
27 | Accepted | 257ms | 112716 KiB | ||||
28 | Accepted | 252ms | 112636 KiB | ||||
29 | Wrong answer | 261ms | 112280 KiB | ||||
30 | Wrong answer | 259ms | 112344 KiB | ||||
31 | Accepted | 319ms | 112896 KiB | ||||
32 | Accepted | 317ms | 115436 KiB | ||||
33 | Accepted | 324ms | 117920 KiB | ||||
34 | Accepted | 330ms | 125032 KiB | ||||
35 | Wrong answer | 250ms | 114288 KiB | ||||
36 | Accepted | 244ms | 114096 KiB | ||||
37 | Accepted | 243ms | 113832 KiB | ||||
38 | Accepted | 331ms | 113924 KiB | ||||
39 | Wrong answer | 331ms | 113724 KiB | ||||
40 | Wrong answer | 237ms | 113132 KiB |