| Task: | Distances |
| Sender: | andr1y |
| Submission time: | 2021-01-30 15:05:46 +0200 |
| Language: | C++ (C++17) |
| 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.02 s | 2 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:38:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(auto i : res) cout<<i<<' ';cout<<'\n';
^~~
input/code.cpp:38:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(auto i : res) cout<<i<<' ';cout<<'\n';
^~~~Code
// -- //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 120;
vector<ll> d[N];
ll p[N];
ll dp[N][N], n;
void dfs(ll v, ll p, ll sv, ll len){
dp[sv][v]=len;
for(auto i : d[v]){
if(i!=p) dfs(i, v, sv, len+1);
}
}
vector<ll> res;
void d2(ll v, ll p=-1, bool mk=0){
if(!mk) res.push_back(v);
for(auto i : d[v]){
if(i!=p) d2(i, v, !mk);
}
if(mk) res.push_back(v);
}
signed main(){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
ll q;
cin >> q;
while(q--){
cin >> n;
for(ll i = 1;i<=n;i++) d[i].clear(), p[i]=i;
res.clear();
for(ll a, b, i=1;i<n;i++){
cin >> a >> b;
d[a].push_back(b);
d[b].push_back(a);
}
for(ll i = 1;i<=n;i++) dfs(i, -1, i, 0);
d2(1);
for(auto i : res) cout<<i<<' ';cout<<'\n';
/*do{
bool ok =1;
for(ll i = 2;i<=n;i++){
ok=ok&&dp[p[i-1]][p[i]]<4;
}
if(ok){
for(ll i = 1;i<=n;i++) cout<<p[i]<<' ';cout<<'\n';
break;
}
}while(next_permutation(p+1, p+n+1));*/
}
}
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 |
