#P13003. [GCJ 2022 Finals] Slide Parade
[GCJ 2022 Finals] Slide Parade
题目描述
Gooli is a huge company that owns buildings in a hilly area, numbered 1 through . Six years ago, Gooli built slides that allowed employees to go from one building to another. Each slide allows anyone to go from the slide's origin building to the slide's destination building, but not the other way around. Gooli's CEO is very proud of their slides and wants to organize a parade through the slides. She has tasked Melek, Gooli's Head of Transportation and a problem-solving enthusiast, with designing the parade's route.
She has some requirements for the parade route in mind:
- It must start and end at building 1, where her office is located.
- It must visit each building the same number of times. Being in building 1 at the start of the route does not count as a visit.
- It must use each slide at least once.
- It must have at most steps.
Given the layout of buildings and slides, help Melek find a route that satisfies all of the CEO's requirements, if one exists.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing two integers and : the number of buildings and slides, respectively. Then, lines follow. The -th of these lines contains two integers and , indicating that the -th slide goes from building to building .
输出格式
For each test case, output one line containing Case #x: y
, where is the test case number (starting from 1). If there is no route that fulfills all the requirements, must be IMPOSSIBLE
. If there is, must be an integer between and , inclusive, representing the length of one such route you want to exhibit. In that case, output another line containing integers , where is the -th building in your proposed route. Notice that and that each building must appear the same number of times among the , except for building 1, which appears exactly one extra time.
5
2 2
2 1
1 2
3 4
2 3
1 2
3 2
1 3
3 6
1 2
1 3
2 1
2 3
3 1
3 2
3 4
1 2
2 1
1 3
3 1
4 6
1 2
1 4
2 3
3 2
3 4
4 1
Case #1: 7
1 2 1 2 1 2 1
Case #2: IMPOSSIBLE
Case #3: 7
1 2 3 1 3 2 1
Case #4: IMPOSSIBLE
Case #5: 9
1 4 1 2 3 2 3 4 1
提示
Sample Explanation
In Sample Case #1, another acceptable parade route is one that goes from building 1 to building 2 and then back for a total of 2 steps.
In Sample Case #2, there are no slides leading to building 1, so no valid parade can exist.
In Sample Case #3, the parade route the sample output exhibits goes through each building twice.
Sample Case #4 is pictured below.
Sample Case #5 is the one illustrated in the problem statement. In the parade route in the sample output, the slides from 2 to 3 and from 4 to 1 are used twice, but the rest of the slides are used only once each.
Limits
- .
- , for all .
- , for all .
- , for all .
- $(\mathbf{U}_i, \mathbf{V}_i) \neq (\mathbf{U}_j, \mathbf{V}_j)$, for all .
Test Set 1 (11 Pts, Visible Verdict)
- Time limit: 10 seconds.
- .
- .
Test Set 2 (24 Pts, Hidden Verdict)
- Time limit: 20 seconds.
- .
- .