12942022-03-30 16:23:44Valaki2Multiplikátoros telebabrátorcpp14Runtime error 20/100151ms65592 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2020 KiB
2Accepted115ms64880 KiB
subtask220/20
3Accepted118ms64880 KiB
4Accepted118ms64872 KiB
5Accepted115ms64912 KiB
6Accepted123ms64944 KiB
7Accepted127ms65112 KiB
8Accepted112ms65132 KiB
9Accepted109ms65180 KiB
10Accepted111ms65224 KiB
11Accepted142ms65264 KiB
12Accepted143ms65388 KiB
13Accepted151ms65592 KiB
14Accepted81ms65384 KiB
15Accepted78ms65368 KiB
16Accepted75ms65392 KiB
subtask30/80
17Runtime error1ms2676 KiB
18Runtime error1ms2724 KiB
19Runtime error1ms2736 KiB
20Runtime error1ms2756 KiB
21Runtime error1ms2772 KiB
22Runtime error1ms2792 KiB
23Runtime error2ms2804 KiB
24Runtime error1ms2816 KiB
25Runtime error1ms2836 KiB
26Runtime error2ms2848 KiB
27Runtime error1ms2868 KiB
28Runtime error1ms2888 KiB
29Runtime error1ms2896 KiB
30Runtime error1ms2912 KiB
31Runtime error1ms2932 KiB
32Runtime error1ms2956 KiB
33Runtime error1ms2976 KiB
34Runtime error2ms2992 KiB
35Runtime error1ms3012 KiB
36Runtime error1ms3024 KiB
37Runtime error1ms3040 KiB
38Runtime error1ms3056 KiB
39Runtime error1ms3068 KiB
40Runtime error1ms3080 KiB