a dfs solution