func bfs(emit chan int, root int, arcs [][]int) { var ( n = len(arcs) seen = make([]bool, n) curr = []int{root} next []int ) for seen[root] = true; ; { for _, from := range curr { emit <- from for _, to := range arcs[from] { if !seen[to] { seen[to] = true next = append(next, to) } } } if len(next) == 0 { break } curr, next = next, curr } close(emit) }
To receive a hint, submit unfixed code.