Submission #31709937


Source Code Expand

import heapq
n, m, x = map(int, input().split())
t = [0] * n
for i in range(n):
    t[i] = int(input())
e = [[] for i in range(n)]
for i in range(m):
    a, b, d = map(int, input().split())
    e[a - 1].append([b - 1, d])
    e[b - 1].append([a - 1, d])
cost = [[[10 ** 9] * (x + 1) for j in range(2)] for i in range(n)]
# cost[i][j][k] = 今頂点 i にいて以前に j (0: 寒すぎる,1: 暑すぎる) の部屋にいて,温度差の大きい部屋に入れるようになるまでの残り時間が k であるときの,ここまでの経過時間の最小値
q = []
cost[0][0][x] = 0
heapq.heappush(q, [0, 0, 0, x])
while len(q) != 0:
    d, v, a, b = heapq.heappop(q)
    if cost[v][a][b] != d:
        continue
    for u, c in e[v]:
        if t[u] == 0:
            if a == 1 and b - c > 0:
                continue
            if cost[u][0][x] > d + c:
                cost[u][0][x] = d + c
                heapq.heappush(q, [d + c, u, 0, x])
        if t[u] == 1:
            if cost[u][a][max(0, b - c)] > d + c:
                cost[u][a][max(0, b - c)] = d + c
                heapq.heappush(q, [d + c, u, a, max(0, b - c)])
        if t[u] == 2:
            if a == 0 and b - c > 0:
                continue
            if cost[u][1][x] > d + c:
                cost[u][1][x] = d + c
                heapq.heappush(q, [d + c, u, 1, x])
answer = 10 ** 9
for i in range(x + 1):
    answer = min(answer, cost[n - 1][0][i], cost[n - 1][1][i])
print(answer)

Submission Info

Submission Time
Task F - ヘビの JOI 君 (Snake JOI)
User Pro_ktmr
Language PyPy3 (7.3.0)
Score 100
Code Size 1512 Byte
Status AC
Exec Time 568 ms
Memory 117168 KiB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 568 ms 97556 KiB
data2 AC 423 ms 106320 KiB
data3 AC 485 ms 113964 KiB
data4 AC 567 ms 116552 KiB
data5 AC 489 ms 117168 KiB