| Task: | Distances |
| Sender: | AMnu |
| Submission time: | 2021-01-30 01:20:48 +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.01 s | 2 | details |
Code
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e2+5;
int T, N;
vector <int> V[MAXN];
void dfs(int par,int now,bool last) {
if (!last) {
cout<<now<<' ';
}
for (int next : V[now]) {
if (next==par) continue;
dfs(now,next,!last);
}
if (last) {
cout<<now;
if (par==0) {
cout<<'\n';
}
else {
cout<<' ';
}
}
}
int main() {
cin>>T;
for (int i=1;i<=T;i++) {
cin>>N;
for (int j=1;j<N;j++) {
int x, y;
cin>>x>>y;
V[x].push_back(y);
V[y].push_back(x);
}
dfs(0,1,1);
for (int j=1;j<=N;j++) {
V[j].clear();
}
}
}
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 |
|---|
| 4 3 5 6 2 7 8 1 3 8 2 7 5 6 4 1 4 3 8 7 2 5 6 1 6 3 8 2 4 7 5 1 6 8 3 2 5 7 4 1 ... 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 |
|---|
| 22 60 44 37 17 5 55 71 59 24 3... Truncated |
