implement connected block question based on graphic BFS