結果

問題 No.2431 Viral Hotel
ユーザー chineristACchineristAC
提出日時 2023-08-18 22:21:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,244 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 114,460 KB
最終ジャッジ日時 2024-11-28 08:04:58
合計ジャッジ時間 29,484 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import *

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,K,M,P = mi()
edge = [[] for v in range(N)]
for _ in range(M):
    u,v = mi()
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)
S = [int(input()) for i in range(N)]

infect = [False] * N
immune = [False] * N
check = [False] * N
for _ in range(K):
    x = int(input())
    infect[x-1] = True

event_pq = []
for i in range(N):
    if infect[i]:
        heappush(event_pq,(S[i],2,i))
        heappush(event_pq,(P,1,i))

while event_pq:
    t = event_pq[0][0]
    cure = []
    spread = []
    while event_pq and event_pq[0][0] == t:
        _,e,i = heappop(event_pq)
        if check[i]:
            continue
        if e == 1:
            cure.append(i)
        else:
            spread.append(i)
    
    #print(t,cure,spread)
    
    for i in cure:
        infect[i] = False
        immune[i] = True
    
    t_check = []
    for v in spread:
        for nv in edge[v]:
            if check[nv]:
                continue
            
            if not immune[nv]:
                if not infect[nv]:
                    infect[nv] = True
                    heappush(event_pq,(t+S[nv],2,nv))
                    heappush(event_pq,(t+P,1,nv))
                else:
                    t_check.append(nv)
    
    for v in t_check:
        check[v] = True

ans = 0
for i in range(N):
    ans += int(check[i])

print(ans)





0