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;
int tmm = 0;
void dfs(int cur, int pr, vector<int>& tin, vector<int>& tout, vector<int>& d, vector<vector<int>>& ed) {
tin[cur] = tmm++;
d[cur] = d[pr] + 1;
for (auto to : ed[cur]) {
if (to == pr) continue;
dfs(to, cur, tin, tout, d, ed);
}
tout[cur] = tmm++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<vector<int>> ed(n);
for (int i = 0; i < n-1; ++i) {
ed[u[i]].push_back(v[i]);
ed[v[i]].push_back(u[i]);
}
vector<int> d(n), tin(n), tout(n);
tmm = 0, d[0] = -1;
dfs(0, 0, tin, tout, d, ed);
vector<int> label(n);
for (int i = 0; i < n; ++i){
if (d[i] % 2 == 0) label[i] = tin[i];
else label[i] = tout[i];
}
return label;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if (s < c[0]){
int prev = s;
for (int i = 0; i < c.size() - 1; ++i){
if (prev <= t && t <= c[i]) return c[i];
prev = c[i];
}
return c.back();
} else{
int prev = s;
for (int i = c.size() - 1; i > 0; --i){
if (c[i] <= t && t <= prev) return c[i];
prev = c[i];
}
return c[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | 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... |