#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, int label) {
	labels[u] = label;
	sort(adj[u].begin(), adj[u].end());
	int child_label = label + 1;
	for (auto &v : adj[u]) {
		if (v == p) continue;
		dfs(v, u, child_label);
		if (u == p) child_label += 1000;
		else child_label++;
	}
}
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;
	if (deg[root] <= 2) FOR(i, 0, n) if (deg[i] == 1) root = i;
	labels.assign(n, 0);
	dfs(root, root, 0);
	// 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");
	if (s == 0) {
		return c[t / 1000];
	}
	if (t < s) return c[0];
	if (s / 1000 == t / 1000) return c[1];
	else 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... |