dfs_order = [] function dfs(v): append v to the back of dfs_order pick an arbitrary permutation s of children of v for child in s: dfs(child) dfs(1)