【发布时间】:2016-09-12 19:14:22
【问题描述】:
在给定的图形G=(V,E) 中,每条边都有一个成本c(e)。我们有一个起始节点 s 和一个目标节点 t。我们如何使用以下 BFS 算法找到从 s 到 t 的边数最少的最昂贵路径?
BFS(G,s):
foreach v in V do
color[v] <- white; parent[v] <- nil
color[s] <- grey; parent[s] <- s
BFS-Visit(s)
BFS-Visit(u):
Q <- empty queue
Enqueue(Q,u)
while Q != empty do
v <- Dequeue(Q)
foreach w in Adj[v] do
if color[w] white then
color[w] <- grey
parent[w] <- v
Enqueue(Q,w)
color[v] <- black
【问题讨论】:
标签: algorithm graph-theory breadth-first-search