#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++;
	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.resize(n);
	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");
	int ans = 0;
	
	if (c.size() == 2) {
		if (s == 0) ans = t < c[1] ? c[0] : c[1];
		else ans = c[1] == t ? c[1] : c[0];
	} else if (c.size() == 1) {
		ans = c[0];
	} else {
		int width = c[2] - c[1];
		if (t < c[1]) ans = c[0];
		else if (t < c[2]) ans = c[1];
		else if (t < c[2] + width) ans = c[2];
		else ans = c[0];
	}
	// dbg("ans is: "); dbg(ans); dbg("\n");
	return ans;
}
| # | 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... |