問題一覧 > 通常問題

No.2431 Viral Hotel

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 43
作問者 : bortik / テスター : 0214sh7 noya2 👑 potato167 tassei903 ponjuice
お気に入りにしたユーザー ProblemId : 10013 / 自分の提出
問題文最終更新日: 2023-08-17 23:35:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
traP 作問ハッカソンコンテスト 001 (順位表) の他の問題:

Problem Statement

Ookayama Grand Hotel has $N$ rooms, and every room is occupied by $1$ guest. There are also $M$ corridors connecting rooms, and the $i$-th corridor connects room $u_i$ and room $v_i$ $(i =1,...,M)$.

One day, the $K$ guests staying in rooms $x_1,\cdots,x_K$ are simultaneously infected with the novel coronavirus. Each guest has an incubation period of $s_j (j = 1,...,N)$ days.

At the start of each day, the following events occur in this order.

1. If a guest was infected $P$ days ago, that guest recovers and acquires immunity. Once a guest has acquired immunity, that guest is never infected by the virus again.

2. When $s_j$ days have passed since the guest in room $j$ was infected, that guest infects the guests in the rooms adjacent to room $j$ (rooms connected by a corridor) with the novel coronavirus, unless they have immunity. Note that a guest who has already recovered still infects others.

3. If a guest infected with the virus is infected again before recovering, a quarantine takes place in that room (this includes the case of being infected $2$ or more times on the same day). In this case, the guest leaves the hotel and no longer spreads the virus to adjacent rooms from then on.

When there are no more infected guests in the hotel, how many rooms have been quarantined?

Constraints

  • $1 \le N \le 10^5$
  • $1 \le K \le N$
  • $0 \le M \le \min (10^5, N\times (N-1)/2)$
  • $1 \le P \le 1000$
  • $1 \le u_i,v_i \le N (1 \le i \le M)$
  • $u_i \neq v_i (1 \le i \le M)$
  • $\{u_i,v_i\} \neq \{u_j,v_j\} (i \neq j)$
  • $1 \le s_j \le P (1\le j\le N)$
  • $1 \le x_i \le N (1 \le i \le K)$
  • $x_i \neq x_j (i \neq j)$
  • All inputs are integers.

Input

$N$ $K$ $M$ $P$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$
$s_1$
$s_2$
$\vdots$
$s_N$
$x_1$
$x_2$
$\vdots$
$x_K$

Output

Output the answer.

Sample

Sample 1
Input
6 2 5 2
1 2
2 3
3 4
4 5
5 6
1
1
1
1
1
1
1
5
Output
1

On day $0$, the virus appears in room $1$ and room $5$.

On day $1$, the guests in rooms $2,4,6$ are infected with the virus.

On day $2$, the guests in rooms $1,5$ recover, and the guest in room $3$ catches the virus from two people, so a quarantine takes place in room $3$ and the guest in room $3$ leaves the hotel.

On day $3$, the guests in rooms $2,4,6$ recover, and there are no more infected guests in the hotel.

Only room $3$ was quarantined, so the answer is $1$.

Sample 2
Input
5 1 4 3
1 2
1 3
1 4
1 5
2
1
1
1
1
1
Output
0

The guest in room $1$ recovers just before being infected by other guests, so room $1$ is not quarantined.

Sample 3
Input
4 2 4 4
1 2
3 1
4 1
2 3
1
4
4
3
2
3
Output
1

Room $1$ is quarantined. Once quarantined, it no longer spreads the virus, so the guest in room $4$ is not infected with the virus.

Sample 4
Input
14 3 16 5
1 2
2 3
2 9
3 8
3 4
4 7
4 5
5 11
5 6
7 8
8 9
9 10
10 11
10 12
12 13
12 14
2
2
3
1
2
3
4
5
4
2
4
1
2
1
1
3
11
Output
7

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。