結果

問題 No.1601 With Animals into Institute
ユーザー H3PO4H3PO4
提出日時 2021-07-10 14:36:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,137 ms / 3,000 ms
コード長 907 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 84,796 KB
実行使用メモリ 140,972 KB
最終ジャッジ日時 2023-09-14 19:26:51
合計ジャッジ時間 19,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
70,700 KB
testcase_01 AC 76 ms
70,856 KB
testcase_02 AC 75 ms
70,984 KB
testcase_03 AC 150 ms
78,668 KB
testcase_04 AC 138 ms
78,312 KB
testcase_05 AC 147 ms
78,744 KB
testcase_06 AC 1,059 ms
140,972 KB
testcase_07 AC 1,092 ms
140,680 KB
testcase_08 AC 1,063 ms
140,604 KB
testcase_09 AC 1,090 ms
139,788 KB
testcase_10 AC 1,068 ms
139,140 KB
testcase_11 AC 1,069 ms
139,384 KB
testcase_12 AC 1,093 ms
139,632 KB
testcase_13 AC 1,137 ms
139,668 KB
testcase_14 AC 1,088 ms
140,060 KB
testcase_15 AC 1,118 ms
140,736 KB
testcase_16 AC 1,108 ms
140,428 KB
testcase_17 AC 1,063 ms
139,092 KB
testcase_18 AC 146 ms
78,900 KB
testcase_19 AC 147 ms
79,172 KB
testcase_20 AC 139 ms
78,052 KB
testcase_21 AC 140 ms
78,816 KB
testcase_22 AC 144 ms
78,916 KB
testcase_23 AC 139 ms
78,240 KB
testcase_24 AC 146 ms
78,552 KB
testcase_25 AC 138 ms
78,248 KB
testcase_26 AC 150 ms
78,908 KB
testcase_27 AC 75 ms
70,908 KB
testcase_28 AC 76 ms
71,048 KB
testcase_29 AC 76 ms
71,104 KB
testcase_30 AC 77 ms
70,976 KB
testcase_31 AC 77 ms
70,968 KB
testcase_32 AC 77 ms
70,984 KB
testcase_33 AC 78 ms
71,044 KB
testcase_34 AC 76 ms
70,904 KB
testcase_35 AC 76 ms
70,940 KB
testcase_36 AC 77 ms
70,908 KB
testcase_37 AC 76 ms
70,700 KB
testcase_38 AC 77 ms
70,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappush, heappop

input = sys.stdin.buffer.readline
INF = 10 ** 15


def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist


N, M = map(int, input().split())
G = [[] for _ in range(2 * N)]

for _ in range(M):
    A, B, C, X = map(int, input().split())
    A -= 1
    B -= 1
    G[A].append((B, C))
    G[B].append((A, C))
    G[A + N].append((B + N, C))
    G[B + N].append((A + N, C))
    if X:
        G[A].append((B + N, C))
        G[B].append((A + N, C))
        G[A + N].append((B, C))
        G[B + N].append((A, C))

dist = dijkstra(2 * N, G, 2 * N - 1)
print(*dist[:N - 1], sep='\n')
0