-->
当前位置:首页 > 题库

PROGRAMMING:Exterminate the evil cult

Luz5年前 (2021-05-10)题库578
After destroying the branch helm of the cult, Yang Fan, a knight errant of the five elements, put forward a proposal: set up an organ in the branch helm of the cult, then lure the troops of the cult into the organ array, turn off the engine, and destroy the troops of the cult at one stroke. The plan was unanimously approved by the whole party. Yang Fan took out a total of N parts required by the installation mechanism and told you two precautions for installation:
1. Some components need to be installed while others are installed. For example, to install the pulley, the bracket must be installed first.
2. When some parts can be installed, the parts with smaller number should be installed first.
Because there are so many components to install, they want you to write a program to help calculate the correct order of installation. Can you do it?
###Input format:
The first line of input is a number T, which indicates the number of different mechanisms to be installed. Next, it contains the information of T organs. The first line of each group is two numbers N and m (1 < = n < = 100000,0 < = m < = 100000), and the next line is two numbers AI and Bi (1 < = AI, Bi < = n), which means that the installation of the bi component is the first step to install the AI component.
###Output format:
Contains T lines, each line is an arrangement, indicating a sequence of installation, each part number is separated by a space character. If there is no solution, it outputs a - 1.
###Input example:
Here is a set of inputs. For example:
```in
three
7 10
2 1
3 1
4 1
5 2
6 2
5 3
6 3
6 4
7 5
7 6
5 0
3 3
1 2
2 3
3 1
```
###Output example:
```out
1 2 3 4 5 6 7
1 2 3 4 5
-1
```
Note: there are spaces after each number.







answer:If there is no answer, please comment