the breath-first search on a graph