Task: | Distances |
Sender: | TryMax |
Submission time: | 2021-01-30 16:39:57 +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
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize ("O3") //#pragma GCC optimize ("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC optimize ("trapv") //#pragma GCC optimize ("sse, ssse, sse2, avx") #define f first #define s second #define pb push_back #define ld long double #define int long long using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7, inf = 1e18 + 10; vector<int> a[N], ans; void dfs(int u, int pr, int c){ if(c == 0) ans.pb(u + 1); for(auto v : a[u]) if(v != pr) dfs(v, u, 1 - c); if(c == 1) ans.pb(u + 1); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--){ int n; cin >> n; for(int i = 0; i < n; ++i) a[i].clear(); ans.clear(); for(int i = 0; i < n - 1; ++i){ int u, v; cin >> u >> v; a[u - 1].pb(v - 1); a[v - 1].pb(u - 1); } dfs(0, -1, 0); for(auto v : ans) cout << v << " "; 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 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 ... 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 81 59 5 71 55 17 24 13... Truncated |