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 <vector>
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
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> id(n);
int ord = 0;
function<void(int, int, int)> dfs = [&](int v, int p, int depth)
{
if (depth % 2 == 0) id[v] = ord++;
for (int i:adj[v]) {
if (i != p) dfs(i, v, depth + 1);
}
if (depth % 2 == 1) id[v] = ord++;
};
dfs(0, -1, 0);
return id;
}
int find_next_station(int s, int t, std::vector<int> c) {
int parity = -1;
if (c[0] > s) parity = 0;
else parity = 1;
sort(c.begin(), c.end());
if (s) {
if (parity == 0) {
if (t < s || c[c.size()-2] < t) return c.back();
}
else {
if (t < c[1] || s < t) return c[0];
}
}
if (parity == 0) {
for (int i = 0; i < (int)c.size(); i++) {
if (t <= c[i]) return c[i];
}
}
else {
for (int i = (int)c.size() - 1; i >= 0; i--) {
if (t >= c[i]) return c[i];
}
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
# | 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... |