Recently, I'm asked to write a program to solve a problem below.
Describe
Given a tree, two requirements,
- Traverse all nodes starting from root node. In the same time, you should guarantee every edge has been visited twice.
- Especially, leaf nodes should be visited as the order given.
Input
- first line: integer K, represents number of nodes, K >= 1 && K <= 300
- K-1 lines: each line contains two integers, represents an edge(Node ID is 1, 2, 3 .., 1 represents ID of root node).
- last line: All the leaf nodes in order(leaf nodes should be visited in this order).
Output
If you can traverse the tree meeting two requirements above, outputs that node sequence. Otherwise, outputs
-1