首页 > 解决方案 > 算法有什么作用?isGood 的作用是什么?

问题描述

我知道这是 Dijkstra 的算法,但我无法弄清楚IsGood.

输入:无向图,所有G=(V;E)的边权重属于,一个顶点属于。le > 0eEsV

输出:对于每个 vertex v,一个布尔值IsGood[v]

for each vertex v do
    cost[v]  = infinite // integer array indexed by elements of V
    IsGood[v] =  TRUE
end for

cost[s] = 0
MakeEmptyPriorityQueue(Q)

for each v belongs to V do
    InsertPriorityQueue(Q; v; cost[v])
end for

while IsNotEmpty(Q) do
    u  = DeleteMin(Q)
    for each edge e = (u; v) belongs to E, leaving u do
        if cost[v] > cost[u] + le then
            cost[v]  = cost[u] + le
            DecreaseKey(Q; v; cost[v])
            IsGood[v] = IsGood[u]
        else
            IsGood[v] = FALSE
        end if
    end for
end while

标签: algorithmoutputdijkstra

解决方案


推荐阅读