Problem p00140 (C++)

Buggy submission (status: Runtime Error):
#include <climits>
#include <iostream>
#include <memory>
#include <vector>
class Bus_stop {
public:
  Bus_stop(const int &i) : id{i}, mins(10, INT_MAX - 1), prevs(10, nullptr) {
    mins.at(i) = 0;
  };
  //?¬?????????????????¨????
  void set_next(Bus_stop &other) {
    // this ?????? other ????????????????????????
    sub_next(
        other); // other
                // ???????????????????¨???????????£????????????????????????????
  }
  //??¨??????????????¢?´¢
  void search_route() {
    call_sub_search(
        mins); // private???????????????mins???virtual??¢??°?????±??§???????????????????????????
  };
  std::vector<int> get_route(const int &from, const int &to) const {
    return move(to)->sub_route(from);
  }

protected:
  // Bus_stop???ID
  int id;
  //?????????????????´??°??¨????¬??????¢?´¢???????§?????????????
  void sub_search(Bus_stop *next, const std::vector<int> &ms) {
    if (next->renew(ms, this)) { //?????????????????´??°????????£??????
      next->search_route();      //?¬??????¢?´¢???????§?
    }
  }

private:
  //???????????????????°??????????
  std::vector<int> mins;
  //????°???????????????¨???"???????????????"??????????????????
  std::vector<Bus_stop *> prevs;
  // mins??¨prevs?????´??°?????´??°???????????°true???????????°false
  bool renew(const std::vector<int> &prev, Bus_stop *from) {
    bool res = false;
    for (auto i = 0; i < prev.size(); ++i) {
      if (prev.at(i) + 1 < mins.at(i)) {
        mins.at(i) = prev.at(i) + 1;
        prevs.at(i) = from;
        res = true;
      }
    }
    return res;
  }
  //?????????????§????
  const Bus_stop *move(const int &to) const {
    if (to == id) {
      return this;
    } else {
      return prevs.at(to)->move(to);
    }
  }
  std::vector<int> sub_route(const int &from) const {
    if (from == id) {
      return std::vector<int>{from};
    } else {
      auto res = prevs.at(from)->sub_route(from);
      res.push_back(id);
      return res;
    }
  }
  //?¬???????????????????????????¢?´¢
  virtual void call_sub_search(const std::vector<int> &) = 0;
  //?¬?????????????????¨????
  virtual void sub_next(Bus_stop &) = 0;
};
class Loop_stop : public Bus_stop {
public:
  Loop_stop(const int &i) : Bus_stop(i), next{nullptr} {};

private:
  void sub_next(Bus_stop &other) override { next = &other; }
  void call_sub_search(const std::vector<int> &mins) override {
    sub_search(next, mins);
  }
  Bus_stop *next;
};
class Line_stop : public Bus_stop {
public:
  Line_stop(const int &i) : Bus_stop(i), next1{nullptr}, next2{nullptr} {};

private:
  void sub_next(Bus_stop &other) override {
    if (next1) {
      next2 = &other;
    } else {
      next1 = &other;
    }
  }
  void call_sub_search(const std::vector<int> &mins) override {
    sub_search(next1, mins);
    sub_search(next2, mins);
  }
  Bus_stop *next1, *next2;
};
void show(std::vector<int> &route) {
  std::cout << route.at(0);
  for (auto i = 1; i < route.size(); ++i) {
    std::cout << ' ' << route.at(i);
  }
  std::cout << std::endl;
}
int main() {
  std::vector<std::shared_ptr<Bus_stop>> stops(15, nullptr);
  for (auto i = 0; i < 15; ++i) {
    stops.at(i) =
        std::make_shared<Loop_stop>(Loop_stop((i < 10) ? i : (15 - i)));
  }
  for (auto i = 0; i < 15; ++i) {
    stops.at(i)->set_next(*stops.at((i + 1) % 15));
  }
  stops.at(0)->search_route();
  int n;
  std::cin >> n;
  for (auto i = 0; i < n; ++i) {
    int from, to;
    std::cin >> from >> to;
    auto route1 = stops.at(to)->get_route(from, to);
    auto route2 = stops.at(15 - to)->get_route(from, to);
    if (route1.size() < route2.size()) {
      show(route1);
    } else {
      show(route2);
    }
  }
  return 0;
}

Fixed submission:
#include <climits>
#include <iostream>
#include <memory>
#include <vector>
class Bus_stop {
public:
  Bus_stop(const int &i) : id{i}, mins(10, INT_MAX - 1), prevs(10, nullptr) {
    mins.at(i) = 0;
  };
  //?¬?????????????????¨????
  void set_next(Bus_stop &other) {
    // this ?????? other ????????????????????????
    sub_next(
        other); // other
                // ???????????????????¨???????????£????????????????????????????
  }
  //??¨??????????????¢?´¢
  void search_route() {
    call_sub_search(
        mins); // private???????????????mins???virtual??¢??°?????±??§???????????????????????????
  };
  std::vector<int> get_route(const int &from, const int &to) const {
    return move(to)->sub_route(from);
  }

protected:
  // Bus_stop???ID
  int id;
  //?????????????????´??°??¨????¬??????¢?´¢???????§?????????????
  void sub_search(Bus_stop *next, const std::vector<int> &ms) {
    if (next->renew(ms, this)) { //?????????????????´??°????????£??????
      next->search_route();      //?¬??????¢?´¢???????§?
    }
  }

private:
  //???????????????????°??????????
  std::vector<int> mins;
  //????°???????????????¨???"???????????????"??????????????????
  std::vector<Bus_stop *> prevs;
  // mins??¨prevs?????´??°?????´??°???????????°true???????????°false
  bool renew(const std::vector<int> &prev, Bus_stop *from) {
    bool res = false;
    for (auto i = 0; i < prev.size(); ++i) {
      if (prev.at(i) + 1 < mins.at(i)) {
        mins.at(i) = prev.at(i) + 1;
        prevs.at(i) = from;
        res = true;
      }
    }
    return res;
  }
  //?????????????§????
  const Bus_stop *move(const int &to) const {
    if (to == id) {
      return this;
    } else {
      return prevs.at(to)->move(to);
    }
  }
  std::vector<int> sub_route(const int &from) const {
    if (from == id) {
      return std::vector<int>{from};
    } else {
      auto res = prevs.at(from)->sub_route(from);
      res.push_back(id);
      return res;
    }
  }
  //?¬???????????????????????????¢?´¢
  virtual void call_sub_search(const std::vector<int> &) = 0;
  //?¬?????????????????¨????
  virtual void sub_next(Bus_stop &) = 0;
};
class Loop_stop : public Bus_stop {
public:
  Loop_stop(const int &i) : Bus_stop(i), next{nullptr} {};

private:
  void sub_next(Bus_stop &other) override { next = &other; }
  void call_sub_search(const std::vector<int> &mins) override {
    sub_search(next, mins);
  }
  Bus_stop *next;
};
class Line_stop : public Bus_stop {
public:
  Line_stop(const int &i) : Bus_stop(i), next1{nullptr}, next2{nullptr} {};

private:
  void sub_next(Bus_stop &other) override {
    if (next1) {
      next2 = &other;
    } else {
      next1 = &other;
    }
  }
  void call_sub_search(const std::vector<int> &mins) override {
    sub_search(next1, mins);
    sub_search(next2, mins);
  }
  Bus_stop *next1, *next2;
};
void show(std::vector<int> &route) {
  std::cout << route.at(0);
  for (auto i = 1; i < route.size(); ++i) {
    std::cout << ' ' << route.at(i);
  }
  std::cout << std::endl;
}
int main() {
  std::vector<std::shared_ptr<Bus_stop>> stops(15, nullptr);
  for (auto i = 0; i < 15; ++i) {
    stops.at(i) =
        std::make_shared<Loop_stop>(Loop_stop((i < 10) ? i : (15 - i)));
  }
  for (auto i = 0; i < 15; ++i) {
    stops.at(i)->set_next(*stops.at((i + 1) % 15));
  }
  stops.at(0)->search_route();
  int n;
  std::cin >> n;
  for (auto i = 0; i < n; ++i) {
    int from, to;
    std::cin >> from >> to;
    auto route1 = stops.at(0)->get_route(from, to);
    auto route2 = stops.at(9)->get_route(from, to);
    if (route1.size() < route2.size()) {
      show(route1);
    } else {
      show(route2);
    }
  }
  return 0;
}