| Task: | Distances |
| Sender: | tutis |
| Submission time: | 2021-01-30 19:36:32 +0200 |
| Language: | C++ (C++11) |
| 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
/*input
2
4
1 2
1 3
1 4
3
1 2
2 3
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename X>
using ordered_map = tree<T, X, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename X>
using fast_map = cc_hash_table<T, X>;
//using ull = __uint128_t;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
mt19937_64 rng(123);
const ll mod = 1000000007;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int>adj[n + 1];
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
function<vector<int>(int, int)> dfs = [&](int i, int p)
{
vector<int>c;
for (int j : adj[i])
if (j != p)
c.push_back(j);
if (c.size() == 0)
return vector<int>({i});
vector<int>ret;
ret.push_back(i);
for (int j : c)
{
vector<int>a = dfs(j, i);
reverse(a.begin(), a.end());
for (int v : a)
ret.push_back(v);
}
return ret;
};
for (int i : dfs(1, 1))
cout << i << " ";
cout << "\n";
}
}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 |
