一个 恋爱关系图
胡图图love:98于小美
胡图图love:48何壮壮
胡图图love:99小怪
于小美love:10张帅子
何壮壮love:45张帅子
小怪love:100张帅子
胡图图到张帅子的最短路径
确定不是恋爱路径?
算法实现
先看猛料再看是否实现思路
// 定义深度优先搜索状态
struct DepthFirstSearchFLag {
int index; // 当前索引
bool visited[MaxSize]; // 顶点访问状态
};
// 定义最短路径状态
struct ShortPathFLag {
DepthFirstSearchFLag Flag; // 深度优先搜索状态
int end; // 结束顶点索引
int stepNum; // 步数
int m_Weight; // 当前路径权重
int ArgsWeight; // 参数路径权重
int SevePath[MaxSize]; // 保存路径
int ShortPathValue[MaxSize];// 最短路径值
};
void ShortPath(const Graph& graph, ShortPathFLag &ShortPathFLag) {
int& index = ShortPathFLag.Flag.index;
int& end = ShortPathFLag.end;
auto& visited = ShortPathFLag.Flag.visited