finally i use other's code that i am so weak can't write a dfs