在 Dijkstra 算法的 Wikipedia 页面上,它们标记了访问过的节点,这样它们就不会再次被添加到队列中。但是,如果访问了一个节点,那么到该节点的距离就不会更短,那么检查不是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