結果
| 問題 |
No.2431 Viral Hotel
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2023-08-19 03:41:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 409 ms / 2,000 ms |
| コード長 | 920 bytes |
| コンパイル時間 | 297 ms |
| コンパイル使用メモリ | 82,192 KB |
| 実行使用メモリ | 96,344 KB |
| 最終ジャッジ日時 | 2024-11-28 17:07:06 |
| 合計ジャッジ時間 | 12,330 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
"""
最短経路かな
他の人に感染させるタイミング昇順に見ればいい?
"""
import heapq
import sys
from sys import stdin
N,K,M,P = map(int,stdin.readline().split())
lis = [ [] for i in range(N) ]
for i in range(M):
u,v = map(int,stdin.readline().split())
u -= 1
v -= 1
lis[u].append(v)
lis[v].append(u)
s = [int(stdin.readline()) for i in range(N)]
q = []
d = [float("inf")] * N
for i in range(K):
x = int(stdin.readline())-1
d[x] = 0
heapq.heappush(q , (s[x] , x) )
ans = 0
fix = [-1] * N
while q:
cd,v = heapq.heappop(q)
if fix[v] != -1 and fix[v] < cd:
continue
for nex in lis[v]:
if d[nex] == float("inf"):
d[nex] = cd
heapq.heappush(q , (cd+s[nex],nex))
elif cd < d[nex]+P and fix[nex] == -1:
ans += 1
d[nex] = -1
fix[nex] = cd
print (ans)
SPD_9X2