move solution to dfs way