#P12427. [BalticOI 2025] Tour
[BalticOI 2025] Tour
题目描述
There are many tourist attractions in Toruń. Our tour guides prepared a list of one-way walks connecting meeting points in the city center. The walks are numbered from 1 to and similarly the meeting points are numbered from 1 to . Each walk leads from one meeting point to another and allows the participants to see a single attraction on the way. It might be possible to see the same attraction on different walks and there might be multiple walks between the same pair of meeting points. We would like to organise an interesting tour on our day off.
A tour is a sequence of walks, such that every walk starts at the meeting point where the previous one ends. Furthermore, the last walk ends at the meeting point where the very first walk begins.
We call such a tour interesting if it doesn't contain the same attraction twice in a row. In other words, every two consecutive walks from the tour allow us to see different attractions, and additionally the very first and very last walks from the tour allow us to see different attractions as well. Note that we do not mind if some non-consecutive walks allow us to see the same attraction. In particular, the same walk might be used multiple times on the tour (but not twice in a row).
Your task is to check if it is possible to form an interesting tour, and if so to find one. You can output any interesting tour that consists of at most walks. It can be proven that if there exists an interesting tour, then there exists one consisting of at most walks.
输入格式
The first line contains a positive integer () denoting the number of test cases.
The first line of each test case contains positive integers and (, ) denoting the number of meeting points and walks, respectively.
Each of the subsequent lines describes one of the walks. The -th line contains three positive integers and (, , ), which indicate that the -th walk starts at the meeting point , ends at the meeting point , and allows us to see the attraction .
Let and denote the sum of and , respectively, over all test cases. You can assume that .
输出格式
For each test case, in the first line you should output YES if it is possible to organise an interesting tour and NO otherwise. In the former case, the second line should first contain a positive integer () denoting the number of walks forming the interesting tour. This should be followed by integers separated by single spaces. These numbers should describe an interesting tour, where we first follow walk , then , and so on, and finally we follow walk returning to the original meeting point.
5
3 3
1 2 1
2 3 2
3 1 1
3 3
2 1 1
1 3 3
3 1 2
2 2
1 2 2
1 2 1
5 6
1 2 1
2 3 2
3 1 1
1 4 3
4 5 4
5 1 3
4 4
1 3 4
3 2 1
2 3 2
2 3 2
NO
YES
2 2 3
NO
YES
6 3 4 5 6 1 2
YES
4 2 4 2 3
提示
Illustration of the 4th test case from the example. The arrows represent the walks between meeting points.
Scoring
Subtask | Constraints | Points |
---|---|---|
1 | and | 9 |
2 | 23 | |
3 | 19 | |
4 | 25 | |
5 | No additional constraints. | 24 |