A. Graph
In the case of the tree, the answer is obvious.
Once dfs, will try a different side in the sub-tree merge it.
Consider the case of a non-tree, a tree can be generated.
B. Permutation
In the case of the tree, the answer is obvious.
Once dfs, will try a different side in the sub-tree merge it.
Consider the case of a non-tree, a tree can be generated.