generic implementation of bfs for computing connected components, spanning
trees, ... not yet tested