正在加载图片...
Algorithm for st-distance Initialize:dist(s)=0;dist(u)=oo for all other u, "Q=[s] While 0 is not empty Dequeue the top element u of Q //Enqueue all neighbors v ofu that haven't been covered so far into Q,with dist function updated For all neighbors v of u,if dist(v)=oo, enqueue(v) ■ dist(v)=dist(u)+1 If t is found,then stop and output dist(t) 19Algorithm for 𝑠𝑡-distance ◼ Initialize: 𝑑𝑖𝑠𝑡(𝑠) = 0; 𝑑𝑖𝑠𝑡(𝑢) = ∞ for all other 𝑢, ◼ 𝑄 = [𝑠] ◼ While 𝑄 is not empty ❑ Dequeue the top element 𝑢 of 𝑄 ❑ // Enqueue all neighbors 𝑣 of 𝑢 that haven’t been covered so far into 𝑄, with 𝑑𝑖𝑠𝑡 function updated For all neighbors 𝑣 of 𝑢, if 𝑑𝑖𝑠𝑡(𝑣) = ∞, ◼ enqueue(𝑣) ◼ 𝑑𝑖𝑠𝑡(𝑣) = 𝑑𝑖𝑠𝑡(𝑢) + 1 ❑ If 𝑡 is found, then stop and output 𝑑𝑖𝑠𝑡(𝑡) 19
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有