正在加载图片...
Let's run it step by step together on the board! dist(s)=0;dist(u)=oo for all other u, Q=[s] While Q is not empty Dequeue the top element u of Q For all neighbors v of u, if dist(v)=oo, enqueue(v) dist(v)=dist(u)+1 0 If t is found,then stop and output dist(t) 20Let’s run it step by step together on the board! ◼ 𝑑𝑖𝑠𝑡(𝑠) = 0; 𝑑𝑖𝑠𝑡(𝑢) = ∞ for all other 𝑢, ◼ 𝑄 = [𝑠] ◼ While 𝑄 is not empty ❑ Dequeue the top element 𝑢 of 𝑄 ❑ For all neighbors 𝑣 of 𝑢, if 𝑑𝑖𝑠𝑡(𝑣) = ∞, ◼ enqueue(𝑣) ◼ 𝑑𝑖𝑠𝑡(𝑣) = 𝑑𝑖𝑠𝑡(𝑢) + 1 ❑ If 𝑡 is found, then stop and output 𝑑𝑖𝑠𝑡(𝑡) s t 20
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有