結果

問題 No.2431 Viral Hotel
ユーザー chineristACchineristAC
提出日時 2023-08-18 22:21:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,030 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 114,072 KB
最終ジャッジ日時 2024-05-06 04:36:12
合計ジャッジ時間 25,005 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 798 ms
104,840 KB
testcase_01 AC 701 ms
100,796 KB
testcase_02 AC 748 ms
102,136 KB
testcase_03 AC 800 ms
106,932 KB
testcase_04 AC 827 ms
108,416 KB
testcase_05 AC 959 ms
110,552 KB
testcase_06 AC 91 ms
78,208 KB
testcase_07 AC 100 ms
78,592 KB
testcase_08 AC 95 ms
78,396 KB
testcase_09 AC 41 ms
52,480 KB
testcase_10 AC 41 ms
52,480 KB
testcase_11 AC 39 ms
52,608 KB
testcase_12 AC 1,030 ms
114,072 KB
testcase_13 AC 786 ms
104,992 KB
testcase_14 AC 508 ms
93,568 KB
testcase_15 AC 256 ms
82,756 KB
testcase_16 AC 716 ms
101,272 KB
testcase_17 AC 446 ms
88,576 KB
testcase_18 AC 824 ms
104,896 KB
testcase_19 AC 661 ms
98,524 KB
testcase_20 AC 349 ms
87,608 KB
testcase_21 AC 303 ms
85,120 KB
testcase_22 AC 546 ms
93,472 KB
testcase_23 AC 606 ms
96,184 KB
testcase_24 AC 430 ms
91,056 KB
testcase_25 AC 768 ms
103,148 KB
testcase_26 AC 504 ms
95,744 KB
testcase_27 AC 567 ms
95,244 KB
testcase_28 AC 512 ms
92,032 KB
testcase_29 AC 490 ms
91,648 KB
testcase_30 AC 508 ms
93,116 KB
testcase_31 AC 729 ms
101,156 KB
testcase_32 AC 276 ms
84,308 KB
testcase_33 AC 449 ms
89,856 KB
testcase_34 AC 162 ms
78,828 KB
testcase_35 AC 286 ms
83,556 KB
testcase_36 AC 815 ms
104,708 KB
testcase_37 AC 551 ms
95,144 KB
testcase_38 AC 333 ms
87,272 KB
testcase_39 AC 38 ms
52,608 KB
testcase_40 AC 36 ms
52,608 KB
testcase_41 AC 36 ms
52,736 KB
testcase_42 AC 38 ms
52,352 KB
testcase_43 AC 936 ms
111,808 KB
testcase_44 AC 653 ms
98,700 KB
testcase_45 AC 500 ms
93,512 KB
権限があれば一括ダウンロードができます

ソースコード

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