func spf(root int, arcs [][]int) map[int]int { var ( dist = map[int]int{root: 0} curr = []int{root} next []int ) for { for _, from := range curr { var ( dist1 = dist[from] arcs = arcs[from] n = len(arcs) ) for i := 0; i < n; i += 2 { var ( to = arcs[i] dist2 = arcs[i+1] dist3 = dist1 + dist2 ) dist4, reached := dist[to] if !reached || dist3 < dist4 { dist[to] = dist2 next = append(next, to) } } } if len(next) == 0 { break } curr, next = next, curr[:0] } return dist }
To receive a hint, submit unfixed code.