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

Code

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int N=110;
int dist[N][N];
vector<int>g[N];
vector<int>order;
void dfs(int v,int pr,int c){
    if (c==0) order.push_back(v);
    for (int to:g[v]){
        if (to!=pr){
            dfs(to,v,c^1);
        }
    }
    if (c==1) order.push_back(v);
}
int p[N];
mt19937 rnd(time(NULL));
double random_double(){
    return rnd()%1000000001/1000000000.0;
}
void solve(){
    int n;cin>>n;
    for (int i=0;i<=n;i++) g[i].clear();
    for (int i=1;i<n;i++){
        int a,b;cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    order.clear();
    dfs(1,0,0);
    for (int i:order) cout<<i<<" ";
    cout<<endl;






}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;cin>>tt;
    while (tt--){
        solve();
    }
    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...