CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:Ausca
Submission time:2021-01-29 19:31:29 +0200
Language: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>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)

using namespace std;

using ll = long long;

const int MAXN = 105;
vector<int> adj[MAXN];
vector<int> order;
void dfs(int n, int par, bool skip) {
    if (!skip) {
        order.push_back(n);
    }
    for (int e : adj[n]) {
        if (e != par) {
            dfs(e, n, !skip);
        }
    }
    if (skip) {
        order.push_back(n);
    }
}
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	int T;
	cin >> T;
	while (T-->0) {
        int N;
        cin >> N;
        order.clear();
        FR(i, N) {
            adj[i].clear();
        }
        FR(i, N-1) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        dfs(0, 0, false);
        for (int i = 0; i < N; i++) {
            cout << order[i]+1 << " ";
        }
        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 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 
...

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...