#P13503. [OOI 2024] Evidence Board
[OOI 2024] Evidence Board
题目描述
Volodya dreams of becoming a detective. Therefore, Volodya often reads books that tell incredible stories of solving crimes. Studying the next case, Volodya came across interesting details of the investigation.
There were a total of suspected persons in the case. The evidence board contains all persons. Initially, there were no connections between them.
During the investigation, new connections between suspected persons emerged one after another. Each connection linked two persons that previously had no connection with each other, even indirectly through several other persons.
Let's consider what happened when a connection between persons and emerged. In addition to the names of the persons, each connection had three parameters: --- the strength of the evidence against , --- the strength of the evidence against , and --- the total strength of the evidence of connection. For natural reasons, the strength of the evidence of connection could not exceed the sum of strengths of the evidence against and . That means that for each connection, it was that . Upon receiving such connection, the detectives drew a line on the board between the images of persons and , assigning the to this line. Also, a sticker with the number was placed on the image of person , and a sticker with the number was placed on . If there were already other stickers on the image, the new sticker was placed on top of the old ones.
The case was solved exactly at the moment when all the suspected persons were linked through connections. After solving the crime, the board was placed in the museum in its original form.
Inspired by this approach, Volodya visited that museum and studied the evidence board in detail. Volodya noticed that the image of person contained stickers with numbers numbered . Here, denotes the number of connections associated with person . Also, Volodya remembered that the -th connection was between persons and and had evidence strength . Unfortunately the connections were arbitrarily numbered, and their numbers did not necessarily correspond to the order in which they appeared during the investigation.
Due to the confusion with the numbers of connections, the information on the board did not help to restore the process of the investigation. Now Volodya needs to restore any possible chronological order in which the connections could have emerged for the detectives. This task is too difficult for him, so he asks your help. It is also possible that the museum falsified information, and a suitable order does not exist.
输入格式
The first line of the input contains two integers and (, ) --- the number of suspected persons in the case and the test group number.
The next lines describe the connections. The -th line contains three integers , , and (, , ) --- the persons connected by the -th connection and the total strength of the -th connection. It is guaranteed that connections link all persons together.
The next lines describe the numbers written on the stickers. The -th line contains integers () --- the numbers written on the stickers on the image of the -th person from top to bottom. equals the number of connections associated with person .
输出格式
If there is no suitable chronological order for the restoration of connections according to the conditions of the problem, output (without quotes) on a single line.
Otherwise, on the first line output (without quotes). On the second line, output numbers --- a suitable chronological order of connections to emerge. The connections are numbered from to in the same order as they are given in the input. If there are multiple possible orders, output any of them.
5 0
1 2 3
1 3 1
3 4 12
3 5 6
0 4
2
6 1 3
8
3
Yes
1 4 2 3
7 0
1 2 4
2 3 4
3 4 4
4 5 4
5 6 4
6 7 4
2
1 2
2 3
1 2
3 2
1 2
179
Yes
5 1 2 3 6 4
4 0
1 2 7
1 3 6
1 4 5
3 2 1
5
4
3
No
提示
Note
In the first example, one of the possible orders is . In chronological order, the first connection links and , , --- the evidence is correct. The second connection links and , , --- the evidence is correct. The third connection links and , , --- the evidence is correct. The fourth connection links and , , -- the evidence is correct. For a better understanding, refer to the illustration.
:::align{center}
:::
Scoring
The tests for this problem consist of nine groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.
Group | Points | Additional constraints | < | Required Groups | Comment |
---|---|---|---|---|---|
0 | -- | -- | -- | Examples. | |
1 | 10 | 0 | -- | ||
2 | 15 | -- | for all | -- | |
3 | 8 | for all | |||
4 | 9 | for all | 3 | ||
5 | 7 | for all | -- | ||
6 | for all and | ||||
7 | 17 | -- | $\displaystyle\sum_{v=1}^{n} \displaystyle\sum_{i=1}^{deg_v} c_{v,i} = \displaystyle\sum_{i=1}^{n-1} w_i$ | ||
8 | 16 | -- | 0, 1, 5, 6 | ||
9 | 11 | -- | 0 -- 8 | Offline-evaluation |