CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:ScarletS
Submission time:2021-01-30 19:04:50 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.12 s2details

Code

#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int dist[101][101], e[101];
bitset<101> done,col;

void solve()
{
    int n,x,y;
    cin>>n;
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=n;++j)
            dist[i][j]=200;
        dist[i][i]=e[i]=0;
        done[i]=col[i]=0;
    }
    for (int i=1;i<n;++i)
    {
        cin>>x>>y;
        dist[x][y]=1;
        dist[y][x]=1;
        ++e[x];
        ++e[y];
    }
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for (int i=1;i<=n;++i)
        if (e[i]==1)
            x=i;
    for (int i=1;i<=n;++i)
        if (dist[1][i]&1)
            col[i]=1;
    vector<int> v;
    v.push_back(x);
    bool ok;
    while (1)
    {
        x=v.back();
        done[x]=1;
        ok=1;
        cout<<x<<" ";
        for (int i=1;i<=n&&ok;++i)
            if (dist[x][i]<4&&!done[i]&&col[i])
            {
                ok=0;
                v.push_back(i);
                break;
            }
        for (int i=1;i<=n&&ok;++i)
            if (dist[x][i]==2&&!done[i])
            {
                ok=0;
                v.push_back(i);
                break;
            }
        for (int i=1;i<=n&&ok;++i)
            if (dist[x][i]==3&&!done[i])
            {
                ok=0;
                v.push_back(i);
                break;
            }
        for (int i=1;i<=n&&ok;++i)
            if (dist[x][i]==1&&!done[i])
            {
                ok=0;
                v.push_back(i);
                break;
            }
        if (ok)
            break;
    }
    cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    while (n--)
        solve();
    return 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
7 3 4 2 5 6 8 1 
6 3 5 7 8 1 4 
7 8 3 4 6 1 
7 3 6 5 2 1 4 8 
6 8 3 2 4 1 
...
Truncated

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
92 94 97 54 61 6 34 70 56 2 63...
Truncated