이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
}
컴파일 시 표준 에러 (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... |