Logo
(追記) (追記ここまで)

31729번 - Board Game 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB70131017.544%

문제

There is a board game for $K$ players. The board of this game consists of $N$ cells numbered from 1ドル$ to $N,ドル and $M$ paths numbered from 1ドル$ to $M,ドル where path $j$ (1ドル ≤ j ≤ M$) connects cells $U_j$ and $V_j$ bidirectionally.

There are two types of cells on the board: re-activate cells and stop cells.

This information is given by a string $S$ of length $N$ consisting of '0' and '1’, where the $i$-th character of $S$ (1ドル ≤ i ≤ N$) is '0' if cell $i$ is a re-activate cell, and '1' if cell $i$ is a stop cell.

This board game is played by $K$ players numbered from 1ドル$ to $K$. Each player has their own piece, and the game starts with each player placing their piece on a specified cell. At the beginning, player $p$ (1ドル ≤ p ≤ K$) places their piece on cell $X_p$. Note that multiple players’ pieces can be placed on the same cell.

The game progresses with each player taking turns starting from player 1ドル$ and proceeding in numerical order. After player $p$ finishes their turn, the turn moves to player $p + 1$ (if $p = K,ドル then the turn goes to player 1ドル$). Each player takes the following actions on their turn:

  1. Choose one cell connected to the cell where their piece is placed via a path, and move their piece to the chosen cell.
  2. If the destination cell is a re-activate cell, repeat step 1 and continue their turn. If the destination cell is a stop cell, end their turn.

The team consisting of $K$ members, including JOI-Kun, who represent Japan in this board game, are researching cooperative strategies to quickly conquer the game. They are currently studying the following problem:

What is the minimum total number of moves required by the $K$ players in order to place player 1ドル$’s piece on cell $T$? Even if it’s in the middle of a turn, if player 1ドル$’s piece is placed on cell $T,ドル the condition is considered satisfied.

Given the information about the board of the game and the initial placement of each player’s piece, create a program to calculate the answer to this problem for each $T = 1, 2, \dots , N$.

입력

Read the following data from the standard input.

$N$ $M$ $K$

$U_1$ $V_1$

$U_2$ $V_2$

$\vdots$

$U_M$ $V_M$

$S$

$X_1$ $X_2$ $\cdots$ $X_K$

출력

Output $N$ lines to the standard output. On the $T$-th line (1ドル ≤ T ≤ N$), output the minimum total number of moves required by the $K$ players to place player 1ドル$’s piece on cell $T$.

제한

  • 2ドル ≤ N ≤ 50,円 000$.
  • 1ドル ≤ M ≤ 50,円 000$.
  • 2ドル ≤ K ≤ 50,円 000$.
  • 1ドル ≤ U_j < V_j ≤ N$ (1ドル ≤ j ≤ M$).
  • $(U_j , V_j) \ne (U_k, V_k)$ (1ドル ≤ j < k ≤ M$).
  • It is possible to reach any cell from any other cell by traversing several paths.
  • $S$ is a string of length $N$ consisting of '0' and '1'.
  • 1ドル ≤ X_p ≤ N$ (1ドル ≤ p ≤ K$).
  • $N,ドル $M$ and $K$ are integers.
  • $U_j$ and $V_j$ are integers (1ドル ≤ j ≤ M$).
  • $X_p$ is an integer (1ドル ≤ p ≤ K$).

서브태스크

번호배점제한
13

There are no stop cells.

27

There is exactly one stop cell.

37

There are exactly two stop cells.

419

$N ≤ 3,円 000,ドル $M ≤ 3,円 000,ドル $K ≤ 3,円 000$.

523

$K = 2$.

69

$K ≤ 100$.

723

$N ≤ 30,円 000,ドル $M ≤ 30,円 000,ドル $K ≤ 30,円 000$.

89

There are no additional constraints.

예제 입력 1

5 5 2
1 2
2 3
2 4
3 5
4 5
00000
1 5

예제 출력 1

0
1
2
2
3

Since player 1ドル$’s piece starts on cell 1ドル,ドル the answer for $T = 1$ is 0ドル$.

For $T = 2,ドル in the first move, player 1ドル$ can move his piece from cell 1ドル$ to cell 2ドル$. Therefore, the answer for $T = 2$ is 1ドル$.

For $T = 3,ドル they can place player 1ドル$’s piece on cell 3ドル$ with the following 2ドル$ moves:

  • In the first move, player 1ドル$ moves his piece from cell 1ドル$ to cell 2ドル$. Since cell 2ドル$ is a re-activate cell, player 1ドル$’s turn continues.
  • In the second move, player 1ドル$ moves his piece from cell 2ドル$ to cell 3ドル$.

Since they cannot place player 1ドル$’s piece on cell 3ドル$ in 1ドル$ or fewer moves, the answer for $T = 3$ is 2ドル$.

Similarly, it can be verified that the answer for $T = 4$ is 2ドル$ and for $T = 5$ is 3ドル$.

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

예제 입력 2

5 5 2
1 2
2 3
2 4
3 5
4 5
01000
1 5

예제 출력 2

0
1
4
4
5

For $T = 3,ドル they can place player 1ドル$’s piece on cell 3ドル$ with the following 4ドル$ moves:

  • In the first move, player 1ドル$ moves his piece from cell 1ドル$ to cell 2ドル$. Since cell 2ドル$ is a stop cell, it’s player 2ドル$’s turn next.
  • In the second move, player 2ドル$ moves his piece from cell 5ドル$ to cell 3ドル$. Since cell 3ドル$ is a re-activate cell, player 2ドル$’s turn continues.
  • In the third move, player 2ドル$ moves his piece from cell 3ドル$ to cell 2ドル$. Since cell 2ドル$ is a stop cell, it’s player 1ドル$’s turn next.
  • In the fourth move, player 1ドル$ moves his piece from cell 2ドル$ to cell 3ドル$.

Since they cannot place player 1ドル$’s piece on cell 3ドル$ in 3ドル$ or fewer moves, the answer for $T = 3$ is 4ドル$.

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

예제 입력 3

5 5 2
1 2
2 3
2 4
3 5
4 5
01100
1 5

예제 출력 3

0
1
3
3
4

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

예제 입력 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

4
2
3
0
10
1
17
24

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

예제 입력 5

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

예제 출력 5

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

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

힌트

출처

Camp > JOI Spring Training Camp > JOI 2023/2024 Spring Training Camp 2-1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /