#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int timer = -1;
void dfs(int node, int prev, vector<vector<int>> &adj, vector<int> &tin, vector<int> &tout) {
tin[node] = ++timer;
for (auto &neighbour : adj[node]) {
if (neighbour == prev) continue;
dfs(neighbour, node, adj, tin, tout);
}
tout[node] = timer;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = i;
return ans;
}
bool ok(int x, int y) {
deque<int> v; v.push_back(x);
while (true) {
int cr = v.front();
if (cr > y) return false;
if (cr == y) return true;
v.pop_front();
v.push_back(x * 2 + 1);
v.push_back(x * 2 + 2);
}
}
int find_next_station(int s, int t, std::vector<int> c) {
for (auto &neighbour : c) {
if (neighbour == (s-1)/2) continue;
if (ok(neighbour, t)) return neighbour;
}
return (s-1)/2;
}