This documentation is automatically generated by online-judge-tools/verification-helper
#include "graph/restore_path.hpp"
s
から t
への最短路を求めたあと, パス上の頂点列を s -> ... -> t
の順に std::vector<int>
に格納して求める
Graph<T> g;
std::vector<int> s = {0}; // 始点の集合
const T INF;
auto [dist, par, root] = dijkstra(g, s, INF);
auto path = restore_path(par, t);
#pragma once
#include <vector>
#include <algorithm>
// restore path from root[t] to t
std::vector<int> restore_path(std::vector<int>& par, int t) {
std::vector<int> path = {t};
while (par[path.back()] != -1) path.emplace_back(par[path.back()]);
std::reverse(path.begin(), path.end());
return path;
}
#line 2 "graph/restore_path.hpp"
#include <vector>
#include <algorithm>
// restore path from root[t] to t
std::vector<int> restore_path(std::vector<int>& par, int t) {
std::vector<int> path = {t};
while (par[path.back()] != -1) path.emplace_back(par[path.back()]);
std::reverse(path.begin(), path.end());
return path;
}