C version of bfs
C version of bsf(modified)