CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:f1x9d
Submission time:2021-01-30 14:58:17 +0200
Language:C++17
Status:READY
Result:29
Feedback
groupverdictscore
#1ACCEPTED29
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2--2details

Compiler report

input/code.cpp:70:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^

Code

#include <bits/stdc++.h>
//#pragma GCC optimize "O3"
///if ((double) ((double)(clock() - cl)/(double)CLOCKS_PER_SEC)>1.85) { break;}
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define ft first
#define sc second
#define pb push_back
#define e '\n'
#define booost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
#define all(x) (x).begin(),(x).end()
#define file(x) freopen(string(string((x)) + ".in").c_str(), "r", stdin); freopen(string(string((x)) + ".out").c_str(), "w", stdout);
#define GG cout << " OPA " << '\n';

using namespace std;
using namespace __gnu_pbds;

typedef pair <int, int> pi;
typedef tree <pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100 + 5;
const int K = 10;
const int KK = 20;
const int INF = 1e18;
const double d_INF = 2000000000.0;
const double EPS = 1e-17;
const int MOD = 1e9 + 7;
const int LOG = 30;

int dist[N][N];
vector <int> g[N];

void dfs(int v, int v1, int pr = 0, int h = 0) {
    dist[v1][v] = h;
    for (auto to : g[v]) {
        if (to == pr) continue;
        dfs(to, v1, v, h + 1);
    }
}

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i ++) g[i].clear();
    for (int i = 1; i < n; i ++) {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    vector <int> p;
    for (int i = 1; i <= n; i ++) {
        dfs(i, i);
        p.pb(i);
    }
    do {
        bool ok = true;
        for (int i = 1; i < n; i ++) {
            if (dist[p[i]][p[i - 1]] > 3) {ok = false; break;}
        }
        if (ok) {
            for (int i = 0; i < n; i ++) cout << p[i] << ' ';
            cout << '\n';
            return;
        }
    } while(next_permutation(all(p)));
}
main () {
    int test = 1;
    booost;
    cin >> test;
    while (test --) {
        solve();
    }
}

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 3 2 4 7 5 6 8 
1 3 2 8 7 5 4 6 
1 3 2 5 7 8 6 4 
1 2 3 4 5 6 7 8 
1 3 2 4 6 8 7 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
(empty)