Task: | Distances |
Sender: | stephan |
Submission time: | 2021-01-30 06:24:04 +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 110 using 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]){ ans.push_back(node); }else{ return ; } vis[node]=true; for(int i : adj[2][node]) sol(i); for(int i : adj[1][node]) sol(i); if(!vis[par[node]]) sol(par[node]); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef LOCAL freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout) ; #endif cin>>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 |
---|
1 8 2 5 6 3 7 4 1 7 2 8 3 6 5 4 1 6 2 7 8 5 3 4 1 8 3 6 2 4 7 5 1 4 7 5 2 3 8 6 ... 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 |
---|
1 99 82 81 59 5 17 55 71 37 39... Truncated |