結果

問題 No.3111 Toll Optimization
ユーザー SPD_9X2
提出日時 2025-04-18 20:33:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,411 ms / 5,000 ms
コード長 1,127 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 82,876 KB
実行使用メモリ 185,652 KB
最終ジャッジ日時 2025-04-18 20:34:38
合計ジャッジ時間 37,501 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
def Dijkstra(lis,start):

    ret = [float("inf")] * len(lis)
    ret[start] = 0
    end_flag = [False] * len(lis)
    end_num = 0
    
    q = [(0,start)]

    while len(q) > 0:

        ncost,now = heapq.heappop(q)

        if end_flag[now]:
            continue

        end_flag[now] = True
        end_num += 1

        if end_num == len(lis):
            break

        for nex,ecost in lis[now]:

            if ret[nex] > ncost + ecost:
                ret[nex] = ncost + ecost
                heapq.heappush(q , (ret[nex] , nex))

    return ret

N,M,K = map(int,input().split())

C = list(map(int,input().split()))

lis = [ [] for i in range(N*(K+1)) ]

for i in range(M):

    u,v = map(int,input().split())
    u -= 1
    v -= 1

    for p in range(K+1):
        lis[u+p*N].append( (v+p*N,C[i]) )
        lis[v+p*N].append( (u+p*N,C[i]) )

        if p != K:
            lis[u+p*N].append( (v+(p+1)*N,0) )
            lis[v+p*N].append( (u+(p+1)*N,0) )

dlis = Dijkstra(lis,0)

ans = dlis[N-1]
for k in range(K+1):
    ans = min(ans, dlis[N-1 + k*N])

if ans == float("inf"):
    ans = -1
print (ans)
0