提出 #31709235


ソースコード 拡げる

from collections import deque
import heapq

# 入力
n, m, k, s = map(int, input().split())
p, q = map(int, input().split())
c = [0] * k
for i in range(k):
    c[i] = int(input()) - 1
e = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    e[a - 1].append(b - 1)
    e[b - 1].append(a - 1)

# 幅優先探索 (危険な町の判定)
dist = [10 ** 9] * n
que = deque()
for c_i in c:
    dist[c_i] = 0
    que.append(c_i)
while len(que) != 0:
    v = que.popleft()
    for u in e[v]:
        if dist[u] == 10 ** 9:
            dist[u] = dist[v] + 1
            que.append(u)

# ダイクストラ法
cost = [10 ** 18] * n
que = []
cost[0] = 0
heapq.heappush(que, [0, 0])
while len(que) != 0:
    d, v = heapq.heappop(que)
    if cost[v] != d:
        continue
    for u in e[v]:
        if dist[u] == 0:
            continue
        if dist[u] <= s:
            c = q
        else:
            c = p
        if cost[u] > d + c:
            cost[u] = d + c
            heapq.heappush(que, [d + c, u])
if dist[n - 1] <= s:
    print(cost[n - 1] - q)
else:
    print(cost[n - 1] - p)

提出情報

提出日時
問題 E - ゾンビ島 (Zombie Island)
ユーザ Pro_ktmr
言語 PyPy3 (7.3.0)
得点 100
コード長 1159 Byte
結果 AC
実行時間 470 ms
メモリ 93036 KiB

ジャッジ結果

セット名 set01 set02 set03 set04 set05
得点 / 配点 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
結果
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
セット名 テストケース
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
ケース名 結果 実行時間 メモリ
data1 AC 74 ms 65712 KiB
data2 AC 279 ms 88840 KiB
data3 AC 137 ms 75796 KiB
data4 AC 470 ms 93036 KiB
data5 AC 470 ms 90072 KiB