#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> graph(n);
for(int i=0; i<n-1; i++){
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
vector<int> labels(n);
int time = 0;
function<void(int, int, bool)> dfs = [&](int node, int parent, bool layerParity){
if(!layerParity){
labels[node] = time++;
}
for(int neigh : graph[node]){
if(neigh == parent) continue;
dfs(neigh, node, !layerParity);
}
if(layerParity){
labels[node] = time++;
}
};
dfs(0, -1, false);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
bool isOutTime = s > c.back();
int parent = isOutTime ? c.front() : c.back();
pair<int, int> range = isOutTime ? make_pair(c[1], s) : make_pair(s, c[c.size() - 2]);
if(range.first <= t && t <= range.second){
if(isOutTime){
return *(upper_bound(c.begin(), c.end(), t) - 1);
}else{
return *lower_bound(c.begin(), c.end(), t);
}
}else{
return parent;
}
}
# | 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... |