Task: | Distances |
Sender: | apostoldaniel854 |
Submission time: | 2021-01-29 22:57:12 +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;using ll = long long;#define pb push_backconst int MAX_N = 100;int sol[1 + MAX_N];vector <int> gr[1 + MAX_N];vector <int> even_stack, order;void dfs_order (int node, int par, int depth) {if (depth & 1)order.pb (node);elseeven_stack.pb (node);for (int son : gr[node])if (son != par)dfs_order (son, node, depth + 1);if (even_stack.back () == node)even_stack.pop_back (), order.pb (node);}void solveTest () {int n;cin >> n;for (int i = 1; i <= n; i++)gr[i].clear ();for (int i = 1; i < n; i++) {int x, y;cin >> x >> y;gr[x].pb (y);gr[y].pb (x);}order.clear ();dfs_order (1, 0, 0);for (int x : order)cout << x << " ";cout << "\n";}int main () {int t;cin >> t;while (t--)solveTest ();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 |
---|
4 3 5 6 2 7 8 1 3 8 2 7 5 6 4 1 4 3 8 7 2 5 6 1 6 3 8 2 4 7 5 1 6 8 3 2 5 7 4 1 ... 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 |
---|
22 60 44 37 17 5 55 71 59 24 3... Truncated |