Task: | Etäisyydet |
Sender: | hltk |
Submission time: | 2021-01-23 17:24:52 +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.86 s | 1, 2 | details |
#2 | RUNTIME ERROR | 0.85 s | 2 | details |
Code
#include <functional> #include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<vector<int>> g(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector<int> dep(n); function<void(int, int)> dfs1 = [&](int s, int e) { for (auto& u : g[s]) { if (u == e) continue; dep[u] = dep[s] + 1; dfs1(u, s); } }; dfs1(0, 0); vector<int> vis(n); function<void(int)> dfs2 = [&](int s) { cout << s + 1 << " "; vis[s] = 1; function<pair<int, int>(int, int, int)> dfs3 = [&](int s, int e, int d) -> pair<int, int> { if (d == 0) return {dep[s], s}; pair<int, int> ret{dep[s], s}; if (vis[s]) ret.first = -1; for (auto& u : g[s]) { if (u == e) continue; ret = max(ret, dfs3(u, s, d - 1)); } return ret; }; auto [d, u] = dfs3(s, s, 3); if (d == -1) return; dfs2(u); }; dfs2(0); cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; for (int i = 0; i < t; ++i) solve(); }
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 |
---|
1 3 6 5 7 6 7 6 7 6 7 6 7 6 7 ... Truncated |
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 |
---|
1 60 93 47 11 12 11 12 11 12 1... Truncated |