Task: | Distances |
Sender: | voventa |
Submission time: | 2021-01-31 14:02:41 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#2 | RUNTIME ERROR | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> #define X first #define Y second #define sz(a) (int)a.size() #define pb push_back #define int long long using namespace std; typedef long long ll; void solve(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) solve(); return 0; } vector <int> g[110]; bitset <110> b; int ans = -1, dd = 0; vector <int> pans; void dfs(int v, int d, int pr) { if (d == 4) return; if (!b[v]) { if (dd < d) { dd = d; ans = v; } } for (auto u : g[v]) { if (pr != u) { dfs(u, d + 1, v); } } } void solve() { b = 0; int n, x, y; cin >> n; for (int i = 0; i < n; ++i) { g[i].clear(); } pans.clear(); for (int i = 0; i < n - 1; ++i) { cin >> x >> y; x--; y--; g[x].pb(y); g[y].pb(x); } for (int i = 0; i < n; ++i) { if (sz(g[i]) <= 1) { b[i] = 1; pans.pb(i + 1); break; } } while (sz(pans) != n) { ans = -1, dd = 0; dfs(pans.back() - 1, 0, -1); b[ans] = 1; pans.pb(ans + 1); } for (auto i : pans) { cout << i << " "; } cout << '\n'; return; }
Test details
Test 1
Group: 1, 2
Verdict: RUNTIME ERROR
input |
---|
100 8 5 2 2 3 3 7 ... |
correct output |
---|
1 8 2 5 6 7 3 4 1 7 2 8 3 6 4 5 1 4 6 2 7 5 8 3 1 8 3 2 4 7 6 5 1 6 4 7 5 2 3 8 ... |
user output |
---|
(empty) |
Test 2
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
(empty) |