remove tailing space
DFS circle detection