VvyLw's Library

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

View the Project on GitHub

:heavy_check_mark: 最短路
(C++/graph/ShortestPath.hpp)

Required by

Verified with

Code

#pragma once

#pragma GCC diagnostic ignored "-Wreorder"

#include <vector>
#include <algorithm>
namespace man {
struct ShortestPath {
private:
    const std::vector<long long> cost;
    const std::vector<int> src;
public:
    ShortestPath(const std::vector<long long> &cost, const std::vector<int> &src): cost(cost), src(src){}
    inline bool is_thru(const int i) const noexcept { return src[i] != -1; }
    inline std::vector<int> path(int i) noexcept {
        std::vector<int> ret;
        for(; i != -1; i = src[i]) {
            ret.emplace_back(i);
        }
        std::ranges::reverse(ret);
        return ret;
    }
    inline std::vector<long long> get() const noexcept { return cost; }
};
}

/**
 * @brief 最短路
 */
#line 2 "C++/graph/ShortestPath.hpp"

#pragma GCC diagnostic ignored "-Wreorder"

#include <vector>
#include <algorithm>
namespace man {
struct ShortestPath {
private:
    const std::vector<long long> cost;
    const std::vector<int> src;
public:
    ShortestPath(const std::vector<long long> &cost, const std::vector<int> &src): cost(cost), src(src){}
    inline bool is_thru(const int i) const noexcept { return src[i] != -1; }
    inline std::vector<int> path(int i) noexcept {
        std::vector<int> ret;
        for(; i != -1; i = src[i]) {
            ret.emplace_back(i);
        }
        std::ranges::reverse(ret);
        return ret;
    }
    inline std::vector<long long> get() const noexcept { return cost; }
};
}

/**
 * @brief 最短路
 */
Back to top page