CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:NewResolution
Submission time:2021-01-30 06:38:04 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED71
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

#include <iostream>
#include <vector>
#include <set>

using namespace std;

int n;
vector<int> adj[100];

void dfs(int x, bool b, int p = -1) {
    if (!b) cout << x + 1 << " ";
    for (int y : adj[x]) {
        if (y == p) continue;
        dfs(y, !b, x);
    }
    if (b) cout << x + 1 << " ";
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t; cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 0; i < n; i++) adj[i].clear();
        for (int i = 0; i < n - 1; i++) {
            int x, y; cin >> x >> y; x--; y--;
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
        dfs(0, 0);
        cout << endl;
    }
    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...