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>
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){}
    bool is_thru(const int i){ return src[i] != -1; }
    std::vector<int> path(int i) {
        std::vector<int> res;
        for(; i != -1; i = src[i]) {
            res.emplace_back(i);
        }
        std::ranges::reverse(res);
        return res;
    }
    std::vector<long long> get() const { return cost; }
};

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

#pragma GCC diagnostic ignored "-Wreorder"

#include <vector>
#include <algorithm>
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){}
    bool is_thru(const int i){ return src[i] != -1; }
    std::vector<int> path(int i) {
        std::vector<int> res;
        for(; i != -1; i = src[i]) {
            res.emplace_back(i);
        }
        std::ranges::reverse(res);
        return res;
    }
    std::vector<long long> get() const { return cost; }
};

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