在Dijkstra算法的维基百科页面上,它们标记了访问过的节点,因此它们不会再次添加到队列中.但是,如果访问了一个节点,那么该节点的距离就越短,那么检查是否alt < dist[v]已经考虑了访问过的节点?我误解了访问集的某些内容吗?
for each neighbor v of u:
alt := dist[u] + dist_between(u, v); // accumulate shortest dist from source
if alt < dist[v] && !visited[v]:
dist[v] := alt; // keep the shortest dist from src to v
previous[v] := u;
insert v into Q; // Add unvisited v into the Q to be processed
end if
end for
Run Code Online (Sandbox Code Playgroud)