#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;
int timer = 0;
vi tin, tout;
void dfs(int u, int p) {
tin[u] = timer++;
for (auto &v : adj[u]) {
if (v == p) continue;
dfs(v, u);
}
tout[u] = timer;
labels[u] = tin[u] * 1000 + tout[u];
}
vi label(int N, int K, vi x, vi y) {
n = N; k = K;
U = x; V = y;
cur_label = 0;
tin.assign(n, 0); tout.assign(n, 0);
timer = 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]);
}
labels.assign(n, 0);
dfs(0, 0);
trace(labels); dbg("\n");
return labels;
}
inline bool is_ancestor(int s, int t) {
int stin = s / 1000, stout = s % 1000;
int ttin = t / 1000, ttout = t % 1000;
// dbg("s = "); dbg(s); dbg(" t = "); dbg(t); dbg("\n");
// dbg("tin[s] = "); dbg(stin); dbg(" tout[s] = "); dbg(stout); dbg("\n");
// dbg("tin[t] = "); dbg(ttin); dbg(" tout[t] = "); dbg(ttout); dbg("\n");
return stin <= ttin && stout >= ttout;
}
inline bool is_root(int s) {
return (s / 1000) == 0;
}
inline int get_parent(int s, vi &c) {
for (auto el : c) {
if (is_ancestor(el, s)) {
return el;
}
}
return s;
}
int find_next_station(int s, int t, vi c) {
// dbg("s: "); dbg(s); dbg(" t: "); dbg(t); dbg(" c: "); trace(c); dbg("\n");
if (!is_root(s) && !is_ancestor(s, t)) {
int parent = get_parent(s, c);
// dbg("parent is: "); dbg(parent); dbg("\n");
return parent;
}
for (auto &el : c) {
if (!is_root(s) && el == get_parent(s, c)) continue;
if (!is_ancestor(el, t)) continue;
return el;
}
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... |