CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:Jarif_Rahman
Submission time:2021-01-31 12:42:25 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.01 s2details

Code

#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
vector<vector<int>> v;
vector<int> order;
void solve(){
    int n; cin >> n;
    v.assign(n, {}), order.clear();
    for(int i = 1; i < n; i++){
        int a, b; cin >> a >> b; a--, b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    vector<bool> bl(n, 0);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int nd = q.front(); q.pop();
        bl[nd] = 1;
        for(int x: v[nd]) if(!bl[x]) q.push(x);
        order.pb(nd+1);
    }
    for(int x: order) cout << x << " ";
    cout << "\n";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T; cin >> T; while(T--) solve();
}

Test details

Test 1

Group: 1, 2

Verdict:

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 4 8 3 2 7 5 6 
1 3 5 7 6 4 8 2 
1 4 3 6 8 2 5 7 
1 6 5 8 2 4 7 3 
1 6 8 4 3 7 2 5 
...

Test 2

Group: 2

Verdict:

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 22 45 99 30 60 82 44 19 81 6...