CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:smjleo
Submission time:2021-02-01 16:47:55 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED71
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int mod = 1000000007;
const int mod2 = 998244353;
// change this
const int N = 105;
int t, n, a, b;
vector<int> arr[N], ans;
void dfs(int node, int par, int flag) {
if (!flag) ans.push_back(node);
for (auto i : arr[node]) {
if (i == par) continue;
dfs(i, node, flag^1);
}
if (flag) ans.push_back(node);
}
signed main() {
io;
cin >> t;
while (t--) {
ans.clear();
cin >> n;
for (int i=1; i<=n; i++) arr[i].clear();
for (int i=0; i<n-1; i++) {
cin >> a >> b;
arr[a].push_back(b);
arr[b].push_back(a);
}
dfs(1, 0, 0);
for (auto i : ans) cout << i << ' ';
cout << nl;
}
}

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