Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. BestPath(u):
  2.     min = MAX_INT
  3.     is_leaf = False
  4.     path = {}
  5.  
  6.     child_list = Children(u)
  7.     if child_list == {}:
  8.         is_leaf = True
  9.         path = {u}
  10.         min = 0
  11.     else:
  12.         for v in child_list:
  13.             c_path, small_sum, is_leaf = BestPath(v)
  14.  
  15.             big_sum = Dist(u, v) + small_sum
  16.  
  17.             if (is_leaf and big_sum < min) or (not is_leaf and big_sum < small_sum and big_sum < min):
  18.                 path = {u} + c_path
  19.                 min = big_sum
  20.             else if (big_sum > small_sum) and (small_sum < min):
  21.                 path = c_path
  22.                 min = small_sum
  23.  
  24.     return path, min, is_leaf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement