#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(x) (cout << (x))
#else
#define dbg(x)
#endif
typedef long long ll;
using vi =vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define trace(x) for (auto &el : x) {dbg(el); dbg(" ");}
int n, k;
vi U, V, labels;
vvi adj;
int cur_label = 0;
void dfs(int u, int p) {
// labels[u] = cur_label++;
labels[u] = u;
sort(adj[u].begin(), adj[u].end());
for (auto &v : adj[u]) {
if (v == p) continue;
dfs(v, u);
}
}
vi label(int N, int K, vi x, vi y) {
n = N; k = K;
U = x; V = y;
cur_label = 0;
adj.assign(n, vi());
vi deg(n); for (int i = 0; i < n - 1; i++) {
deg[U[i]]++, deg[V[i]]++;
adj[U[i]].push_back(V[i]);
adj[V[i]].pb(U[i]);
}
int root = 0;
// FOR(i, 1, n) if (deg[i] == 2) root = i;
labels.assign(n, 0);
dfs(root, root);
// trace(labels); dbg("\n");
return labels;
}
int find_next_station(int s, int t, vi c) {
// dbg("s: "); dbg(s); dbg(" t: "); dbg(t); dbg(" c: "); trace(c); dbg("\n");
while (t != 0) {
if (c.size() >= 2 && t == c[1]) return c[1];
if (c.size() >= 3 && t == c[2]) return c[2];
t = (t - 1) / 2;
}
return c[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |