serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 経路復元
(library/graph/route_restore.hpp)

経路復元

できること

計算量

$O(L)$

使い方

auto [dis, route] = dijkstra(G, {s});
vector<int> pth = route_restore(route, goal);

Verified with

Code

#pragma once
vector<int> route_restore(const vector<int> &route, int goal) {
    vector<int> path = {goal};
    while (!!~route[path.back()]) path.push_back(route[path.back()]);
    reverse(path.begin(), path.end());
    return path;
}
#line 2 "library/graph/route_restore.hpp"
vector<int> route_restore(const vector<int> &route, int goal) {
    vector<int> path = {goal};
    while (!!~route[path.back()]) path.push_back(route[path.back()]);
    reverse(path.begin(), path.end());
    return path;
}
Back to top page