CSES - Datatähti 2021 loppu - Results
Submission details
Task:Etäisyydet
Sender:Anttono
Submission time:2021-01-23 20:14:05 +0200
Language:C++11
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.03 s1, 2details
#2--2details

Compiler report

input/code.cpp: In function 'int verify(std::vector<int>)':
input/code.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<tv.size()-1;i++)
                 ~^~~~~~~~~~~~
input/code.cpp: In function 'int depth(int, int, int)':
input/code.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

Code

#include <bits/stdc++.h>

using namespace std;

#define N 101

int t,n;
vector<int> v[N];
int z[N];

void clearz()
{
    for(int i=0;i<N;i++)
    {
        z[i] = 0;
    }
}

void clearv()
{
    for(int i=0;i<N;i++)
    {
        v[i].resize(0);
    }
}

int depth(int n, int g, int cd)
{
    if(z[n]) return -1;
    z[n] = 1;
    for(auto u : v[n])
    {
        if(u == g) return cd;
        int dr = depth(u, g, cd+1);
        if(dr>0) return dr;
    }
}

int verify(vector<int> tv)
{
    for(int i=0;i<tv.size()-1;i++)
    {
        if(depth(tv[1], tv[i+1], 0)>3) return 0;
        clearz();
    }
    return 1;
}

int main()
{
    cin>>t;
    for(int o=0;o<t;o++)
    {
        cin>>n;
        vector<int> tv;
        int a,b;
        for(int i=1;i<n;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
            tv.push_back(i);
        }
        tv.push_back(n);

        do
        {
            if(verify(tv)) break;
        }while(next_permutation(tv.begin(), tv.end()));

        for(int i=0;i<n;i++)
        {
            cout<<tv[i]<<" ";
        }
        cout<<endl;

        clearv();
        clearz();
        n = 0;
    }
}

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

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
(empty)