Task: | Distances |
Sender: | stephan |
Submission time: | 2021-01-30 05:59:33 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 29 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | TIME LIMIT EXCEEDED | -- | 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[N]; vector<int> adj1[N]; bool vis[N]; int cur=0; int cnt=0; void md(int node,int parent,int d){ adj[cur].push_back(node); if(d==3) return ; for(int i : adj1[node]) if(i!=parent) md(i,node,d+1); } vector<int> ans; void bk(){ if(cnt==n) return; int last=cur; for(int i : adj[cur]) { if(!vis[i]){ cur=i; cnt++; vis[i]=true; ans.push_back(i); bk(); if(cnt==n) return ; vis[i]=false; cur=last; cnt--; ans.pop_back(); } } cur=last; } 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[i].clear(); adj1[i].clear(); vis[i]=false; } ans.clear(); for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; adj1[a].push_back(b); adj1[b].push_back(a); } for(int i=1;i<=n;i++){ cur=i; md(i,-1,0); } cur=1; cnt=1; ans.push_back(1); vis[1]=true; bk(); for(int i : ans) cout<<i<<" "; cout<<"\n"; } return 0; }
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 4 8 3 2 5 7 6 1 3 8 2 7 5 6 4 1 4 3 6 8 2 5 7 1 6 8 2 3 4 5 7 1 6 8 4 3 7 2 5 ... Truncated |
Test 2
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
(empty) |