結果
問題 | No.2431 Viral Hotel |
ユーザー |
👑 ![]() |
提出日時 | 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 heapqimport sysfrom sys import stdinN,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 -= 1v -= 1lis[u].append(v)lis[v].append(u)s = [int(stdin.readline()) for i in range(N)]q = []d = [float("inf")] * Nfor i in range(K):x = int(stdin.readline())-1d[x] = 0heapq.heappush(q , (s[x] , x) )ans = 0fix = [-1] * Nwhile q:cd,v = heapq.heappop(q)if fix[v] != -1 and fix[v] < cd:continuefor nex in lis[v]:if d[nex] == float("inf"):d[nex] = cdheapq.heappush(q , (cd+s[nex],nex))elif cd < d[nex]+P and fix[nex] == -1:ans += 1d[nex] = -1fix[nex] = cdprint (ans)