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 <algorithm>
#include <vector>
using namespace std;
int dfs(
vector<vector<int>> const& graph,
vector<int>& label,
int const cur,
int start,
bool const left,
int const par
) {
int sz = 1;
if (left) {
label[cur] = start;
start++;
}
for (int const neigh : graph[cur]) {
if (neigh == par)
continue;
int const neigh_sz = dfs(graph, label, neigh, start, !left, cur);
sz += neigh_sz;
start += neigh_sz;
}
if (!left)
label[cur] = start;
return sz;
}
vector<int> label(int const n, int const k, vector<int> const u, vector<int> const 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> label(n, -1);
dfs(graph, label, 0, 0, true, -1);
return label;
}
int find_next_station(int const s, int const t, vector<int> c) {
bool const left = s < c[0];
if (left) {
if (t < s)
return c.back();
for (int i = 0; i < c.size() - 1; i++)
if (c[i] >= t)
return c[i];
return c.back();
}
else {
reverse(c.begin(), c.end());
if (t > s)
return c.back();
for (int i = 0; i < c.size() - 1; i++)
if (c[i] <= t)
return c[i];
return c.back();
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
stations.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < c.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# | 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... |