CP-templates

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Misuki743/CP-templates

:heavy_check_mark: graph/shortest_path/path_recover.cpp

Verified with

Code

vi recover(vi &pre, int t) {
  if (pre[t] == -1) return {};
  vi path = {t};
  while(pre[path.back()] != path.back())
    path.emplace_back(pre[path.back()]);
  ranges::reverse(path);
  return path;
}
#line 1 "graph/shortest_path/path_recover.cpp"
vi recover(vi &pre, int t) {
  if (pre[t] == -1) return {};
  vi path = {t};
  while(pre[path.back()] != path.back())
    path.emplace_back(pre[path.back()]);
  ranges::reverse(path);
  return path;
}
Back to top page