CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:andr1y
Submission time:2021-01-30 14:57:15 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.01 s2details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:41:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
         for(auto i : res) cout<<i<<' ';cout<<'\n';
         ^~~
input/code.cpp:41:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
         for(auto i : res) cout<<i<<' ';cout<<'\n';
                                        ^~~~

Code

// -- //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 120;
vector<ll> d[N];
bool dnu[N];
ll lval, lvert;
void dfs(ll v, ll p=-1, ll len=0){
    if(!dnu[v]&&len>lval) lval=len, lvert=v;
    if(len==3) return;
    for(auto i : d[v]){
        if(i!=p) dfs(i, v, len+1);
    }
}
signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll q;
    cin >> q;
    while(q--){
        ll n;
        cin >> n;
        for(ll i = 1;i<=n;i++) d[i].clear(), dnu[i]=0;
        for(ll a, b, i=1;i<n;i++){
            cin >> a >> b;
            d[a].push_back(b);
            d[b].push_back(a);
        }
        vector<ll> res;
        res.push_back(1);
        ll v = 1;
        dnu[1]=1;
        for(ll i = 1;i<n;i++){
            lval=0, lvert=v;
            dfs(v);
            ll e = lvert;
            res.push_back(e);
            dnu[e]=1;
            v=e;
        }
        for(auto i : res) cout<<i<<' ';cout<<'\n';
    }
}

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

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 60 81 17 24 44 59 15 13 20 8...