add bfs dfs-flag dfs-set and complete checking size==0 which will not cause segmentation fault