#P10433. [JOIST 2024] 棋盘游戏 / Board Game

[JOIST 2024] 棋盘游戏 / Board Game

Problem Description

There is a board game played by KK players. The board consists of NN cells numbered from 11 to NN and MM paths numbered from 11 to MM. Path jj (1jM1 \le j \le M) connects cell UjU_j and cell VjV_j in both directions.

There are two types of cells on the board: reactivating cells and stopping cells.

This information is given by a string SS of length NN. SS consists of 00 and 11. The ii-th character of SS (1iN1 \le i \le N) is '0' if cell ii is a reactivating cell, and '1' if cell ii is a stopping cell.

This board game is played by KK players numbered from 11 to KK. Each player has their own piece, and the game starts with each player placing their piece on a specific cell. Initially, player pp (1pK1 \leq p \leq K) places their piece on cell XpX_p. Note that multiple players' pieces may be on the same cell.

The game proceeds with the players taking turns, starting from player 11 and continuing in numerical order. After player pp finishes their turn, player p+1p + 1 starts their turn (if p=Kp = K, then player 11 starts their turn). On their turn, each player performs the following:

  1. Choose a cell connected to the cell where their piece currently is by a path, and move their piece to the chosen cell.
  2. If the destination cell is a reactivating cell, repeat step 1 and continue their turn. If the destination cell is a stopping cell, end their turn.

A team of KK members representing Japan in this board game, including JOI-kun, is studying cooperative strategies to conquer this game quickly. They are currently studying the following question:

What is the minimum total number of moves needed by the KK players to place player 11's piece on cell TT? Even if player 11's piece is placed on cell TT in the middle of a turn, it is considered successful.

Given the information about the game board and the initial positions of each player's piece, write a program to compute the answer to the above question for each T=1,2,,NT = 1, 2, \ldots, N.

Input Format

Read the following data from standard input:

  • NN MM KK
  • U1U_1 V1V_1
  • U2U_2 V2V_2
  • ...
  • UMU_M VMV_M
  • SS
  • X1,X2,...,XKX_1, X_2, ..., X_K

Output Format

Output NN lines. On line TT (1TN1 \le T \le N), output the minimum total number of moves required for the KK players to place player 11's piece on cell TT.

5 5 2
1 2
2 3
2 4
3 5
4 5
00000
1 5
0
1
2
2
3
5 5 2
1 2
2 3
2 4
3 5
4 5
01000
1 5
0
1
4
4
5
5 5 2
1 2
2 3
2 4
3 5
4 5
01100
1 5

0
1
3
3
4
8 7 5
1 3
5 7
4 6
2 6
2 3
7 8
1 5
10011010
4 6 4 7 1
4
2
3
0
10
1
17
24
12 13 3
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 10
2 9
7 12
11 12
110000011101
1 9 11

0
1
4
5
6
7
8
8
4
1
13
9

Hint

Sample Explanation 1

Since player 11's piece starts from cell 11, the answer for T=1T = 1 is 00.

For T=2T = 2, in the first move, player 11 can move their piece from cell 11 to cell 22. Therefore, the answer for T=2T = 2 is 11.

For T=3T = 3, they can place player 11's piece on cell 33 in the following 22 moves:

  • In the first move, player 11 moves their piece from cell 11 to cell 22. Since cell 22 is a reactivating cell, player 11's turn continues.
  • In the second move, player 11 moves their piece from cell 22 to cell 33.

Since they cannot place player 11's piece on cell 33 in 11 move or less, the answer for T=3T = 3 is 22.

Similarly, it can be verified that the answer for T=4T = 4 is 22, and the answer for T=5T = 5 is 33.

This sample input satisfies the constraints of subtasks 1,4,5,6,7,81, 4, 5, 6, 7, 8.

Sample Explanation 2

For T=3T = 3, they can place player 11's piece on cell 33 in the following 44 moves:

  • In the first move, player 11 moves their piece from cell 11 to cell 22. Since cell 22 is a stopping cell, it is then player 22's turn.
  • In the second move, player 22 moves their piece from cell 55 to cell 33. Since cell 33 is a reactivating cell, player 22's turn continues.
  • In the third move, player 22 moves their piece from cell 33 to cell 22. Since cell 22 is a stopping cell, it is then player 11's turn.
  • In the fourth move, player 11 moves their piece from cell 22 to cell 33.

Since they cannot place player 11's piece on cell 33 in 33 moves or less, the answer for T=3T = 3 is 44.

This sample input satisfies the constraints of subtasks 2,4,5,6,7,82, 4, 5, 6, 7, 8.

Sample Explanation 3

This sample input satisfies the constraints of subtasks 3,4,5,6,7,83, 4, 5, 6, 7, 8.

Sample Explanation 4

This sample input satisfies the constraints of subtasks 4,6,7,84, 6, 7, 8.

Sample Explanation 5

This sample input satisfies the constraints of subtasks 4,6,7,84, 6, 7, 8.

Constraints

  • 2N50,0002 \leq N \leq 50,000
  • 1M50,0001 \leq M \leq 50,000
  • 2K50,0002 \leq K \leq 50,000
  • 1Uj<VjN1 \leq U_j < V_j \leq N (1jM1 \leq j \leq M)
  • (Uj,Vj)(U_j, V_j), (Uk,Vk)(U_k, V_k) (1j<kM1 \leq j < k \leq M) are distinct.
  • It is possible to reach any cell from any other cell by traversing one or more paths.
  • SS is a string of length $N consisting of '0' and '1'.
  • 1XpN1 \leq X_p \leq N (1pK1 \leq p \leq K)
  • NN, MM, and KK are integers.
  • UjU_j and VjV_j are integers (1jM1 \leq j \leq M).
  • XpX_p is an integer (1pK1 \leq p \leq K).

Subtasks

  1. (3 points) There are no stopping cells.
  2. (7 points) There is exactly one stopping cell.
  3. (7 points) There are exactly two stopping cells.
  4. (19 points) N3,000N \leq 3,000, M3,000M \leq 3,000, K3,000K \leq 3,000
  5. (23 points) K=2K = 2
  6. (9 points) K100K \leq 100
  7. (23 points) N30,000N \leq 30,000, M30,000M \leq 30,000, K30,000K \leq 30,000
  8. (9 points) No additional constraints.

Translated by ChatGPT 5