You are given a simple directed graph with vertices numbered . The graph is connected when all edge directions are ignored.
Choose some edges of to form a rooted spanning tree satisfying all of the following conditions.
A proper ancestor of a vertex is an ancestor other than the vertex itself.
The following figure shows one valid example. Red edges are tree edges directed from parents to children. Blue edges are non-tree edges directed from descendants to ancestors.
Find a parent sequence satisfying the conditions, or report that none exists.
The input is given in the following format:
If a valid tree exists, print separated by spaces on one line. The parent of the root must be printed as .
Choose vertex as the root and the red edges in the figure as tree edges. Every blue edge points from a descendant to an ancestor.
No rooted spanning tree satisfies all conditions.
The -th edge is directed from to .
If there are multiple solutions, print any of them.
If no valid tree exists, print -1 on one line.
When , the single value -1 is a valid parent sequence.
| 3 | 29 |
|
| 4 | 51 | No additional constraints. |