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

Compiler report

input/code.cpp:81: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];
int n;
bool ok = false;
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 rec(int v, vector <int> p, int cur = 1) {
p[v] = cur;
if (ok) return;
if (cur == n) {
set <pi> s;
for (int i = 1; i <= n; i ++) {
s.insert({p[i], i});
}
for (auto it : s) cout << it.sc << ' ';
cout << '\n';
ok = true;
return;
}
for (int i = 1; i <= n; i ++) {
if (p[i] == 0 && dist[v][i] <= 3) rec(i, p, cur + 1);
}
}
void solve() {
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(n + 1);
int st = 1;
for (int i = 1; i <= n; i ++) {
dfs(i, i);
if (g[i].size() == 1) st = i;
}
ok = false;
rec(st, 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
7 2 3 1 4 8 5 6 
6 1 3 2 8 7 5 4 
7 2 3 1 4 6 5 8 
7 1 2 3 4 5 6 8 
6 1 3 2 4 8 7 5 
...
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
(empty)