Dfs Algorithm Python Stack Overflow