#ifndef INC_07_BFS_AND_SHORTEST_PATH_SHORTESTPATH_H
#define INC_07_BFS_AND_SHORTEST_PATH_SHORTESTPATH_H
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <cassert>
using namespace std;
// 寻找无权图的最短路径
template <typename Graph>
class ShortestPath{
private:
Graph &G; // 图的引用
int s; // 起始点
bool *visited; // 记录dfs的过程中节点是否被访问
int *from; // 记录路径, from[i]表示查找的路径上i的上一个节点
int *ord; // 记录路径中节点的次序。ord[i]表示i节点在路径中的次序。
public:
// 构造函数, 寻找无权图graph从s点到其他点的最短路径
ShortestPath(Graph &graph, int s):G(graph){
// 算法初始化
assert( s >= 0 && s < graph.V() );
visited = new bool[graph.V()];
from
广度优先遍历和最短路径
最新推荐文章于 2023-10-08 13:40:36 发布