func BFS(g Graph, id ID) []ID {
	if _, err := g.GetNode(id); err != nil {
		return nil
	}

	q := []ID{id}
	visited := make(map[ID]bool)
	visited[id] = true
	rs := []ID{id}

	// while Q is not empty:
	for len(q) != 0 {

		u := q[0]
		q = q[1:len(q):len(q)]

		// for each vertex w adjacent to u:
		cmap, _ := g.GetTargets(u)
		for _, w := range cmap {
			// if w is not visited yet:
			if _, ok := visited[w.ID()]; !ok {
				q = append(q, w.ID())  // Q.push(w)
				visited[w.ID()] = true // label w as visited

				rs = append(rs, w)
			}
		}
		pmap, _ := g.GetSources(u)
		for _, w := range pmap {
			// if w is not visited yet:
			if _, ok := visited[w.ID()]; !ok {
				q = append(q, w.ID())  // Q.push(w)
				visited[w.ID()] = true // label w as visited

				rs = append(rs, w.ID())
			}
		}
	}

	return rs
}
func BFS(g Graph, id ID) []ID {
	if _, err := g.GetNode(id); err != nil {
		return nil
	}

	q := []ID{id}
	visited := make(map[ID]bool)
	visited[id] = true
	rs := []ID{id}

	// while Q is not empty:
	for len(q) != 0 {

		u := q[0]
		q = q[1:len(q):len(q)]

		// for each vertex w adjacent to u:
		cmap, _ := g.GetTargets(u)
		for _, w := range cmap {
			// if w is not visited yet:
			if _, ok := visited[w.ID()]; !ok {
				q = append(q, w.ID())  // Q.push(w)
				visited[w.ID()] = true // label w as visited

				rs = append(rs, w)
			}
		}
		pmap, _ := g.GetSources(u)
		for _, w := range pmap {
			// if w is not visited yet:
			if _, ok := visited[w.ID()]; !ok {
				q = append(q, w.ID())  // Q.push(w)
				visited[w.ID()] = true // label w as visited

				rs = append(rs, w.ID())
			}
		}
	}

	return rs
}
// BFS does breadth-first search, and returns the list of vertices.
// (https://en.wikipedia.org/wiki/Breadth-first_search)
//
//	 0. BFS(G, v):
//	 1.
//	 2. 	let Q be a queue
//	 3. 	Q.push(v)
//	 4. 	label v as visited
//	 5.
//	 6. 	while Q is not empty:
//	 7.
//	 8. 		u = Q.dequeue()
//	 9.
//	10. 		for each vertex w adjacent to u:
//	11.
//	12. 			if w is not visited yet:
//	13. 				Q.push(w)
//	14. 				label w as visited
//