Task: | Distances |
Sender: | mofk |
Submission time: | 2021-01-30 17:34:23 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | ACCEPTED | 71 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[105]; int dad[105]; vector<int> dfs(int u) { vector<int> ret; ret.push_back(u); for (auto v: g[u]) { if (v == dad[u]) continue; dad[v] = u; vector<int> add = dfs(v); reverse(add.begin(), add.end()); for (auto x: add) ret.push_back(x); } return ret; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int ntest; cin >> ntest; while (ntest--) { cin >> n; for (int i = 1; i <= n; ++i) g[i].clear(); for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } memset(dad, 0, sizeof dad); vector<int> ans = dfs(1); for (auto x: ans) cout << x << ' '; cout << endl; } return 0; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
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 8 7 2 5 6 3 4 1 7 2 8 3 4 6 5 1 4 6 5 2 7 8 3 1 7 4 2 8 3 6 5 1 6 4 7 5 2 3 8 ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
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 99 82 68 78 81 13 100 52 32 ... Truncated |