Task: | Distances |
Sender: | stephan |
Submission time: | 2021-01-30 06:56:59 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.01 s | 2 | details |
Code
///By Stephan Ramirez dsramirezc@unal.edu.co#include<bits/stdc++.h>#define ms(a,v) memset(a,v,sizeof a)#define ll long long#define N 110using namespace std;int T;int n;vector<int> adj[4][N];vector<int> adj1[N];bool vis[N];int cur=0;int cnt=0;int par[N];void dfs(int node,int parent){par[node]=parent;for(int i : adj1[node])if(i!=parent){adj[1][node].push_back(i);dfs(i,node);for(int j : adj[1][i])adj[2][node].push_back(j);}}vector<int> ans;void sol(int node){if(vis[node])return ;vis[node]=true;for(int i : adj[2][node]){sol(i);sol(par[i]);}for(int i : adj[1][node])if(adj[1][i].size()==0)if(!vis[i]){ans.push_back(i);vis[i]=true;}ans.push_back(node);sol(par[par[node]]);}int main(){ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);#ifdef LOCALfreopen("in.txt","r",stdin);//freopen("out.txt","w",stdout) ;#endifcin>>T;while(T--){cin>>n;for(int i=1;i<=n;i++){adj[1][i].clear();adj[2][i].clear();adj1[i].clear();vis[i]=false;}for(int i=0;i<n-1;i++){int a,b;cin>>a>>b;adj1[a].push_back(b);adj1[b].push_back(a);}ans.clear();vis[0]=true;dfs(1,0);sol(1);for(int i : ans)cout<<i<<" ";cout<<'\n';}return 0;}
Test details
Test 1
Group: 1, 2
Verdict: WRONG ANSWER
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 |
---|
5 6 2 7 3 4 8 1 2 8 3 7 6 4 5 1 7 2 5 8 3 6 4 1 3 8 2 4 7 6 5 1 5 2 3 8 7 4 6 1 ... Truncated |
Test 2
Group: 2
Verdict: WRONG ANSWER
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
5 55 71 17 52 32 100 13 39 24 ... Truncated |