This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
vector<vector<int>> adj(n);
for(int i=0;i<n-1;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> tin(n), tout(n), dep(n);
int t = 0;
function<void(int,int)> dfs = [&](int u,int p){
tin[u] = t++;
for(auto &v : adj[u]){
if(v == p) continue;
dep[v] = dep[u] + 1;
dfs(v, u);
}
tout[u] = t++;
};
dfs(0, 0);
for(int i=0;i<n;i++){
if(dep[i] % 2 == 0){
labels[i] = tin[i];
}
else{
labels[i] = tout[i];
}
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size() == 1) return c[0];
sort(c.begin(), c.end());
if(c[0] < s){
if(t < c[1] || t > s){
return c[0];
}
for(int i=c.size()-1;i>0;--i){
if(c[i] <= t) return c[i];
}
}
else{
reverse(c.begin(), c.end());
if(t > c[1] || t < s){
return c[0];
}
for(int i=c.size()-1;i>0;--i){
if(c[i] >= t) return c[i];
}
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
54 | }
| ^
# | 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... |