BFS corrected for weighted graphs.