#P9074. [WC/CTS2023] 比赛
[WC/CTS2023] 比赛
Problem Description
There are students, numbered from to . They have joined a total of clubs. For some strange reason, any two clubs share at most one common member.
Now the school wants to organize a contest and have these students stand in a circle. To prevent cheating, the principal wants any three consecutive people on the circle to not come from the same club.
The principal asks you to provide a valid circular arrangement of the students, or state that such an arrangement does not exist.
Input Format
The first line contains a positive integer , which denotes the number of test cases.
For each test case:
The first line contains two non-negative integers , representing the number of students and the number of clubs.
The next lines describe the clubs. In the -th line, the first integer is , the number of members in the -th club, followed by distinct integers , which are the student indices of the members in this club.
Output Format
For each test case, output one line:
If there exists a circular arrangement that satisfies the condition, output integers describing such an arrangement. If there are multiple valid arrangements, you may output any one of them.
If no such circular arrangement exists, output a single integer .
4
5 2
3 1 2 3
3 3 4 5
7 7
3 1 2 4
3 2 3 5
3 3 4 6
3 4 5 7
3 5 6 1
3 6 7 2
3 7 1 3
8 2
4 1 2 3 4
4 5 6 7 8
10 1
10 1 2 3 4 5 6 7 8 9 10
1 3 4 2 5
1 2 3 4 5 6 7
1 5 2 6 3 7 4 8
-1
见附件中的 contest2.in
见附件中的 contest2.ans
Hint
[Sample Explanation #1]
In the official judging, any circular arrangement that satisfies the condition is considered correct, no matter which student the arrangement starts from or which direction it goes.
[Sample Explanation #2]
In this sample, the first test cases satisfy , and the last test cases satisfy .
[Constraints]
For all test points, it is guaranteed that , , , , , , are pairwise distinct, and the property stated in the problem holds (any two clubs share at most one common member).
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | None | ||
| None | Guaranteed | ||
| None | |||
| None | Guaranteed | ||
| None |
You may use chk.cpp from the provided file (problem attachment) to check whether your output is valid. Compile it into an executable named chk before use.
- On Linux, run
./chk <input‐file> <output‐file> <answer‐file>to test. - On Windows, run
chk <input‐file> <output‐file> <answer‐file>to test.
Translated by ChatGPT 5