이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
void rec(int index, int parent, int pre_order, int &number,
  std::vector<std::vector<int>>& con, std::vector<int>& labels) {
  if (pre_order) labels[index] = number++;
  for (int i : con[index]) {
    if (i == parent) continue;
    rec(i, index, !pre_order, number, con, labels);
  }
  if (!pre_order) labels[index] = number++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  std::vector<int> labels(n);
	std::vector<std::vector<int>> con(n, std::vector<int>());
  for (int i = 0; i < u.size(); i++) {
    con[u[i]].push_back(v[i]);
    con[v[i]].push_back(u[i]);
  }
  int number = 0;
  rec(0, -1, true, number, con, labels);
	return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
  if (c[0] > s) {
    // Case 1: node s is in pre_order level.
    // All the neighbors are higher than s.
    if (t < s) {
      // The target is smaller than the source.
      // The target is definitely not in this subtree, go to parent.
      return c.back();
    }
    if (t > c.back()) {
      // The target is higher than the largest neighbor.
      // The target cannot be in this subtree, go to parent.
      return c.back();
    }
    // The target is in this subtree.
    // Pick the smallest child that's at least the target.
    int next = 0;
    while (c[next] < t) next++;
    return c[next];
  }
  // Case 2: node s is in the post_order level.
  if (t < c[0]) {
    // The target is smaller than the pre_order root c[0],
    // thus not in this subtree, go to the root.
    return c[0];
  }
  if (t > s) {
    // The target is higher than this post_order value.
    // Thus it's not in this subtree, go to the root.
    return c[0];
  }
  int next = c.size() - 1;
  while (c[next] > t) next--;
	return c[next];
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i = 0; i < u.size(); 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... |