无权图的单源最短路算法
- 按照递增的顺序找到各个顶点的最短路
dist[W]= S到W的最短距离
dist[S]=0
path[W]= S到W的路上经过的某顶点
void Unweighted(Vertex S)
{
Enqueue(S,Q);
while (!IsEmpty(Q))
{
V=Dequeue(Q);
for (V的每个邻接点W)
if (dist[W]==-1)
{
dist[W]=dist[V]+1;
path[W]=V;
Enqueue(W,Q);
}
}
}
T=O(V+E)