#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 NN chambers in the maze numbered 0,,N10, \ldots, N-1. Dr Wood and the members of her team start in chambers 0,1,,A10, 1, \ldots, A-1 (one person per chamber). There are EE exits: chambers NE,,N1N-E, \ldots, N-1. Initially, the maze contains no open corridors. At each hour (00:00, 01:00, 02:00 and so on, represented by integers 0,1,20, 1, 2 and so on), a new corridor between two chambers opens. This corridor stays open for exactly MM hours minus one minute. Corridors are bi-directional.

Among the NN chambers, BB are booby-trapped. The trap of a chamber triggers as soon as it is connected to at least KK 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 AA, the number of archeologists.
  • The second line contains the integer NN.
  • The third line contains the integer MM.
  • The fourth line contains the integer EE.
  • The fifth line contains the integer TT, the number of hours at which corridors open.
  • The sixth line contains BB, followed by the list of the BB space-separated booby-trapped chambers bib_i.
  • The seventh line contains KK.
  • In the next TT lines, line tt contains two space-separated integers ut,vtu_t, v_t representing a corridor that opens at hour tt and connects chambers utu_t and vtv_t. tt goes from 00 to T1T-1 (inclusive). Multiple corridors can connect the same two chambers. A corridor can connect a chamber to itself.

输出格式

The output should contain AA lines. The ii-th line represents the ii-th archeologist. If the ii-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 00 and the exit is 44. After the corridor 00 22 opens, she goes from chamber 00 to chamber 22. She stays there until the corridor 22 44 opens, which allows her to reach chamber 44 and exit at hour 33.

Sample Explanation 2

There are no booby-traps. Dr Wood (the only archeologist) starts at 00 and the exit is 33. Unfortunately, Dr Wood can only reach chamber 22 after the corridor 22 33 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 00 is to go to chamber 55 at hour 66 using corridors 00 66 and 55 66, then to chamber 77 at hour 77 using the corridor 55 77, and finally reach chamber 88 (an exit) at hour 99 using the corridor 77 88. Note that chamber 77 is booby-trapped, but the wasps only appear at hour 1010, after the first archeologist exited the maze.

The second archeologist starting at 11 can move to chamber 00 at hour 00 and then follow the path of the first archeologist.

The third archeologist starting at 22 can move to chamber 00 at hour 11 and then follow the first two archeologists.

The last archeologist starting at 33 is killed by the wasps at hour 22.

At the end, chambers 1,2,3,4,6,7,8,91, 2, 3, 4, 6, 7, 8, 9 are filled with wasps.

Limits

  • 1A501 \leq A \leq 50;
  • 2N500002 \leq N \leq 50000;
  • 1M1000001 \leq M \leq 100000;
  • 1E1001 \leq E \leq 100;
  • A+ENA + E \leq N (no chamber is both a starting chamber and an exit chamber);
  • 1T5000001 \leq T \leq 500000;
  • 0BN0 \leq B \leq N;
  • 0bi<N0 \leq b_i < N for i=0,,B1i = 0, \ldots, B-1;
  • The bib_i's are unique;
  • 0K<N0 \leq K < N;
  • 0ut<N0 \leq u_t < N for t=0,,T1t = 0, \ldots, T-1;
  • 0vt<N0 \leq v_t < N for t=0,,T1t = 0, \ldots, T-1;