#P15152. [SWERC 2024] Yaxchilán Maze
[SWERC 2024] Yaxchilán Maze
题目描述
Years spent deciphering Mayan glyphs had led Dr Wood, a famous archeologist, to this very moment: inside a chamber of the Yaxchilán maze, in the middle of the Lacandon Jungle, the last undiscovered Mayan codex appeared before her. It was beautiful, protected by jaguar pelt and adorned with jade. However, as soon as she touched it, all the corridors of the maze closed. She was now a prisoner of the maze. Worse, she was not alone, but had a full team of archeologists with her that were also held prisoner in different chambers of the maze.
As she examined the codex, a series of intricate diagrams caught her eye. They depicted the maze, its corridors morphing into different configurations, each aligned with a specific position of the sun. Another set of diagrams showed intricately carved holes in the walls together with a chilling depiction of a giant wasp. A realization dawned on her – the Maya had designed this maze to change with the sun's position, and some chambers were booby-trapped with a giant nest of deadly wasps.
Namely, there are chambers in the maze numbered . Dr Wood and the members of her team start in chambers (one person per chamber). There are exits: chambers . Initially, the maze contains no open corridors. At each hour (00:00, 01:00, 02:00 and so on, represented by integers and so on), a new corridor between two chambers opens. This corridor stays open for exactly hours minus one minute. Corridors are bi-directional.
Among the chambers, are booby-trapped. The trap of a chamber triggers as soon as it is connected to at least other chambers. When triggered, a gigantic swarm of deadly wasps appears in the chamber and immediately spreads to all chambers connected to the booby-trapped chamber. Furthermore, as time progresses, the wasps never disappear from a chamber, and worse, they continue to spread instantaneously from chambers that contain wasps to newly connected chambers. Two chambers are considered connected at a given time when there exists a path of one or multiple open corridors that allows going from one chamber to the other. All the archeologists can move freely and independently from each other using the open corridors at all times. They run fast and can move to any reachable chamber in less than 59 minutes. If an archeologist ends up in a chamber filled with deadly wasps, he or she dies and cannot exit the maze.
The exit chambers behave as the other chambers: they can be filled with wasps and be booby-trapped.
As soon as an archeologist reaches any exit chamber not filled with wasps, she or he exits the maze and its dangers. Can you tell the earliest time when each archeologist can exit the maze?
输入格式
- The first line contains the integer , the number of archeologists.
- The second line contains the integer .
- The third line contains the integer .
- The fourth line contains the integer .
- The fifth line contains the integer , the number of hours at which corridors open.
- The sixth line contains , followed by the list of the space-separated booby-trapped chambers .
- The seventh line contains .
- In the next lines, line contains two space-separated integers representing a corridor that opens at hour and connects chambers and . goes from to (inclusive). Multiple corridors can connect the same two chambers. A corridor can connect a chamber to itself.
输出格式
The output should contain lines. The -th line represents the -th archeologist. If the -th archeologist can exit the maze, it should be the integer representing the earliest hour at which she or he can exit. Otherwise, it should be "IMPOSSIBLE" (without quotes).
1
5
1
1
5
0
0
0 1
0 2
2 3
2 4
0 4
3
1
4
1
1
3
0
0
0 1
2 3
1 2
IMPOSSIBLE
4
10
2
2
11
2 3 7
2
0 1
1 2
2 3
1 4
4 9
5 6
0 6
5 7
1 6
7 8
6 8
9
9
9
IMPOSSIBLE
提示
Sample Explanation 1
There are no booby-traps. Dr Wood (the only archeologist) starts at and the exit is . After the corridor opens, she goes from chamber to chamber . She stays there until the corridor opens, which allows her to reach chamber and exit at hour .
Sample Explanation 2
There are no booby-traps. Dr Wood (the only archeologist) starts at and the exit is . Unfortunately, Dr Wood can only reach chamber after the corridor leading to the exit closed. She cannot exit the maze.
Sample Explanation 3
The fastest path to an exit for the first archeologist starting at is to go to chamber at hour using corridors and , then to chamber at hour using the corridor , and finally reach chamber (an exit) at hour using the corridor . Note that chamber is booby-trapped, but the wasps only appear at hour , after the first archeologist exited the maze.
The second archeologist starting at can move to chamber at hour and then follow the path of the first archeologist.
The third archeologist starting at can move to chamber at hour and then follow the first two archeologists.
The last archeologist starting at is killed by the wasps at hour .
At the end, chambers are filled with wasps.
Limits
- ;
- ;
- ;
- ;
- (no chamber is both a starting chamber and an exit chamber);
- ;
- ;
- for ;
- The 's are unique;
- ;
- for ;
- for ;