1294 | 2022-03-30 16:23:44 | Valaki2 | Multiplikátoros telebabrátor | cpp14 | Runtime error 20/100 | 151ms | 65592 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int maxn = 2000;
int n;
vector<pair<int, int> > g[maxn + 1];
int dist[maxn + 1][maxn + 1];
void dfs(int cur, int par, int root, int cur_dist) {
dist[root][cur] = cur_dist;
for(pair<int, int> nei : g[cur]) {
if(nei.fi != par) {
dfs(nei.fi, cur, root, cur_dist ^ nei.se);
}
}
}
void solve() {
cin >> n;
for(int i = 1; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
g[a].pb(mp(b, c));
g[b].pb(mp(a, c));
}
for(int i = 1; i <= n; i++) {
dfs(i, 0, i, 0);
}
for(int i = 1; i <= n; i++) {
int ans = 1;
for(int j = 1; j <= n; j++) {
if(dist[i][j] > dist[i][ans]) {
ans = j;
}
}
cout << ans << " ";
}
cout << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2020 KiB | ||||
2 | Accepted | 115ms | 64880 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 118ms | 64880 KiB | ||||
4 | Accepted | 118ms | 64872 KiB | ||||
5 | Accepted | 115ms | 64912 KiB | ||||
6 | Accepted | 123ms | 64944 KiB | ||||
7 | Accepted | 127ms | 65112 KiB | ||||
8 | Accepted | 112ms | 65132 KiB | ||||
9 | Accepted | 109ms | 65180 KiB | ||||
10 | Accepted | 111ms | 65224 KiB | ||||
11 | Accepted | 142ms | 65264 KiB | ||||
12 | Accepted | 143ms | 65388 KiB | ||||
13 | Accepted | 151ms | 65592 KiB | ||||
14 | Accepted | 81ms | 65384 KiB | ||||
15 | Accepted | 78ms | 65368 KiB | ||||
16 | Accepted | 75ms | 65392 KiB | ||||
subtask3 | 0/80 | ||||||
17 | Runtime error | 1ms | 2676 KiB | ||||
18 | Runtime error | 1ms | 2724 KiB | ||||
19 | Runtime error | 1ms | 2736 KiB | ||||
20 | Runtime error | 1ms | 2756 KiB | ||||
21 | Runtime error | 1ms | 2772 KiB | ||||
22 | Runtime error | 1ms | 2792 KiB | ||||
23 | Runtime error | 2ms | 2804 KiB | ||||
24 | Runtime error | 1ms | 2816 KiB | ||||
25 | Runtime error | 1ms | 2836 KiB | ||||
26 | Runtime error | 2ms | 2848 KiB | ||||
27 | Runtime error | 1ms | 2868 KiB | ||||
28 | Runtime error | 1ms | 2888 KiB | ||||
29 | Runtime error | 1ms | 2896 KiB | ||||
30 | Runtime error | 1ms | 2912 KiB | ||||
31 | Runtime error | 1ms | 2932 KiB | ||||
32 | Runtime error | 1ms | 2956 KiB | ||||
33 | Runtime error | 1ms | 2976 KiB | ||||
34 | Runtime error | 2ms | 2992 KiB | ||||
35 | Runtime error | 1ms | 3012 KiB | ||||
36 | Runtime error | 1ms | 3024 KiB | ||||
37 | Runtime error | 1ms | 3040 KiB | ||||
38 | Runtime error | 1ms | 3056 KiB | ||||
39 | Runtime error | 1ms | 3068 KiB | ||||
40 | Runtime error | 1ms | 3080 KiB |