// not full - need to compress euler tour labels
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first 
#define S second
#include "stations.h"
vector<int> in, out, dep;
vector<vector<int>> adj;
int cnt = 0;
// Euler Tour
void dfs(int n, int p) {
    dep[n] = dep[p]+1;
    in[n] = cnt;
    cnt++;
    for(auto c: adj[n]) {
        if (c != p) dfs(c, n);
    }
    out[n] = cnt;
    cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    in.resize(n);
    out.resize(n);
    dep.resize(n);
    adj.resize(n);
    FOR(i, v.size()) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    dfs(0,0);
    vector<int> res(n);
    FOR(i, n) {
        if (dep[i] % 2) {
            res[i] = in[i];
        } else {
            res[i] = out[i];
        }
    }
    return res;
}
int find_next_station(int s, int t, vector<int> c) {
    int n = c.size();
    // if s_entry <= t <= s_exit, t is in the subtree of s
    if (s < c[0]) { // preorder 
        if (s < t && t <= c[0]) return c[0];
        for(int i = 1; i < n - 1; i++) {
            if (c[i-1] < t && t <= c[i]) return c[i];
        }
        if (s > 0) return c[n-1];
    }
    if (s > c[n-1]) { // postorder
        for(int i = 1; i < n - 1; i++) {
            if (c[i] <= t && t < c[i+1]) return c[i];
        }
        if (c[n-1] <= t && t < s) return c[n-1];
        if (s > 0) return c[0];
    }
}
// signed main() {
//     cin.tie(0); ios::sync_with_stdio(false);
// }
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^| # | 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... |