結果

問題 No.1601 With Animals into Institute
ユーザー 👑 SPD_9X2
提出日時 2021-07-10 14:05:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,280 ms / 3,000 ms
コード長 969 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 81,900 KB
実行使用メモリ 141,500 KB
最終ジャッジ日時 2024-07-02 02:13:18
合計ジャッジ時間 19,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
import sys

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 = map(int,stdin.readline().split())

lis = [ [] for i in range(2*N) ]

for i in range(M):

    A,B,C,X = map(int,stdin.readline().split())

    A -= 1
    B -= 1
    
    lis[A].append( (B+X*N,C) )
    lis[B].append( (A+X*N,C) )

    lis[A+N].append( (B+N,C) )
    lis[B+N].append( (A+N,C) )

dlis = Dijkstra(lis,N-1)

for i in range(N-1):
    print (dlis[i+N])
0