CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:Victor
Submission time:2021-01-30 16:56:05 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = a - 1; i >= (b); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define INF 1000000000
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
vi graph[101];
int n, tc, ans[101], indx, dist;
void solve(int u, int p) {
bool add = true;
if(dist==3){
add=false;
ans[indx++]=u;
dist=0;
}
trav(v, graph[u]) {
if (v == p) continue;
++dist;
solve(v, u);
}
if (add) {
ans[indx++] = u;
dist = 0;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cin >> tc;
int u, v;
while (tc--) {
fill(graph, graph + 101, vi());
cin >> n;
rep(i, 0, n-1) {
cin >> u >> v;
graph[u].pb(v);
graph[v].pb(u);
}
indx = dist = 0;
solve(1, 0);
rep(i,0,n)cout<<ans[i]<<' ';
cout<<endl;
}
return 0;
}

Test details

Test 1

Group: 1, 2

Verdict:

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
3 5 6 2 7 8 4 1 
8 2 7 3 6 4 5 1 
4 8 7 2 5 6 3 1 
3 8 2 4 7 6 5 1 
6 3 5 2 7 4 8 1 
...
Truncated

Test 2

Group: 2

Verdict:

input
100
100
37 59
81 37
44 81
...

correct output
1 99 82 81 59 5 71 55 17 24 13...

user output
60 81 17 5 55 71 59 24 100 52 ...
Truncated