結果

問題 No.1601 With Animals into Institute
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-10 14:05:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,282 ms / 3,000 ms
コード長 969 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 143,068 KB
最終ジャッジ日時 2023-09-14 19:13:30
合計ジャッジ時間 21,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,112 KB
testcase_01 AC 73 ms
71,176 KB
testcase_02 AC 72 ms
71,044 KB
testcase_03 AC 150 ms
79,036 KB
testcase_04 AC 147 ms
78,956 KB
testcase_05 AC 158 ms
79,632 KB
testcase_06 AC 1,172 ms
142,804 KB
testcase_07 AC 1,219 ms
142,912 KB
testcase_08 AC 1,172 ms
142,224 KB
testcase_09 AC 1,238 ms
142,408 KB
testcase_10 AC 1,220 ms
140,912 KB
testcase_11 AC 1,217 ms
141,652 KB
testcase_12 AC 1,193 ms
141,192 KB
testcase_13 AC 1,242 ms
143,068 KB
testcase_14 AC 1,232 ms
141,660 KB
testcase_15 AC 1,261 ms
141,628 KB
testcase_16 AC 1,260 ms
141,728 KB
testcase_17 AC 1,282 ms
142,348 KB
testcase_18 AC 156 ms
79,200 KB
testcase_19 AC 150 ms
78,960 KB
testcase_20 AC 151 ms
78,852 KB
testcase_21 AC 148 ms
79,120 KB
testcase_22 AC 151 ms
78,844 KB
testcase_23 AC 151 ms
78,972 KB
testcase_24 AC 152 ms
78,876 KB
testcase_25 AC 152 ms
78,940 KB
testcase_26 AC 153 ms
79,264 KB
testcase_27 AC 74 ms
71,088 KB
testcase_28 AC 74 ms
71,280 KB
testcase_29 AC 72 ms
71,116 KB
testcase_30 AC 74 ms
70,900 KB
testcase_31 AC 74 ms
70,972 KB
testcase_32 AC 75 ms
71,260 KB
testcase_33 AC 75 ms
71,140 KB
testcase_34 AC 74 ms
71,100 KB
testcase_35 AC 74 ms
70,972 KB
testcase_36 AC 74 ms
71,396 KB
testcase_37 AC 72 ms
71,136 KB
testcase_38 AC 74 ms
71,288 KB
権限があれば一括ダウンロードができます

ソースコード

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