Task: | Distances |
Sender: | zscoder |
Submission time: | 2021-01-30 09:46:13 +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>using namespace std;using namespace __gnu_pbds;#define fi first#define se second#define mp make_pair#define pb push_back#define fbo find_by_order#define ook order_of_keytypedef long long ll;typedef pair<int,int> ii;typedef vector<int> vi;typedef long double ld;typedef pair<ld,ld> state;typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;vi adj[222];int par[222];void dfs(int u, int p=-1){par[u]=p;for(int v:adj[u]){if(v==p) continue;dfs(v,u);}}vi dp[222];void build(int u){vi res = {u};for(int v:adj[u]){build(v);if(adj[v].empty()){res.pb(v);}else{for(int w:adj[v]){vi lul = dp[w];for(int x:lul) res.pb(x);}res.pb(v);}}dp[u]=res;}void solve(){int n; cin>>n;for(int i=0;i<n;i++) dp[i].clear();for(int i=0;i<n-1;i++){int u,v; cin>>u>>v; u--; v--;adj[u].pb(v); adj[v].pb(u);}dfs(0);for(int i=0;i<n;i++) adj[i].clear();for(int i=1;i<n;i++) adj[par[i]].pb(i);build(0);vi res = dp[0];for(int x:res){cout<<x+1<<' ';}cout<<'\n';for(int i=0;i<n;i++) adj[i].clear();}int main(){ios_base::sync_with_stdio(0); cin.tie(0);int t; cin>>t;while(t--) solve();}
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 4 6 5 1 6 2 7 5 8 3 4 1 5 2 4 7 8 3 6 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 12 93 47 11 19 68 78 8... Truncated |