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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:52:12: warning: unused variable 'c' [-Wunused-variable]
     ll a,b,c,d;
            ^
input/code.cpp:52:14: warning: unused variable 'd' [-Wunused-variable]
     ll a,b,c,d;
              ^

Code

#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 400002;

vector<vi> C(MAXN, vi());

void dfs(ll i, ll par, ll d){
    if(d%2 == 0)cout << i+1 << " ";
    trav(y, C[i]){
        if(y != par){
            dfs(y,i,(d+1)%2);
        }
    }
    if(d%2 == 1)cout << i+1 << " ";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("fhc.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> T;

    rep(c4,0,T){

        cin >> n;
        rep(c1,0,n){
            C[c1].clear();
        }
        rep(c1,0,n-1){
            cin >> a >> b;
            a--;b--;
            C[a].push_back(b);
            C[b].push_back(a);
        }
        dfs(0,-1,0);
        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...