結果

問題 No.1601 With Animals into Institute
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-23 19:59:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 988 ms / 3,000 ms
コード長 1,154 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 140,976 KB
最終ジャッジ日時 2024-04-25 11:58:28
合計ジャッジ時間 16,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,608 KB
testcase_01 AC 40 ms
53,120 KB
testcase_02 AC 38 ms
52,864 KB
testcase_03 AC 110 ms
77,688 KB
testcase_04 AC 106 ms
78,016 KB
testcase_05 AC 116 ms
77,952 KB
testcase_06 AC 880 ms
140,848 KB
testcase_07 AC 887 ms
140,588 KB
testcase_08 AC 916 ms
140,608 KB
testcase_09 AC 973 ms
140,148 KB
testcase_10 AC 970 ms
140,780 KB
testcase_11 AC 925 ms
140,016 KB
testcase_12 AC 929 ms
140,012 KB
testcase_13 AC 978 ms
140,796 KB
testcase_14 AC 951 ms
140,564 KB
testcase_15 AC 988 ms
140,316 KB
testcase_16 AC 973 ms
140,976 KB
testcase_17 AC 956 ms
140,760 KB
testcase_18 AC 114 ms
77,488 KB
testcase_19 AC 114 ms
77,972 KB
testcase_20 AC 109 ms
77,696 KB
testcase_21 AC 119 ms
77,628 KB
testcase_22 AC 115 ms
77,952 KB
testcase_23 AC 110 ms
77,568 KB
testcase_24 AC 115 ms
77,724 KB
testcase_25 AC 114 ms
78,496 KB
testcase_26 AC 111 ms
77,588 KB
testcase_27 AC 38 ms
52,864 KB
testcase_28 AC 36 ms
52,480 KB
testcase_29 AC 36 ms
52,992 KB
testcase_30 AC 35 ms
52,864 KB
testcase_31 AC 38 ms
52,736 KB
testcase_32 AC 39 ms
52,736 KB
testcase_33 AC 40 ms
52,992 KB
testcase_34 AC 40 ms
52,608 KB
testcase_35 AC 38 ms
52,608 KB
testcase_36 AC 43 ms
52,608 KB
testcase_37 AC 42 ms
52,608 KB
testcase_38 AC 38 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 10**18

def dijkstra(s, edge):
    n = len(edge)
    dist = [INF]*n
    prev = [-1]*n
    dist[s] = 0
    edgelist = []
    heapq.heappush(edgelist,(dist[s], s))
    while edgelist:
        minedge = heapq.heappop(edgelist)
        if dist[minedge[1]] < minedge[0]:
            continue
        v = minedge[1]
        for e in edge[v]:
            if dist[e[1]] > dist[v]+e[0]:
                dist[e[1]] = dist[v]+e[0]
                prev[e[1]] = v
                heapq.heappush(edgelist,(dist[e[1]], e[1]))
    return dist, prev

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
g = [[] for i in range(2*n)]
for i in range(m):
    a, b, c, x = map(int, input().split())
    a, b = a-1, b-1
    a0, a1, b0, b1 = a, a+n, b, b+n
    if x == 0:
        g[a0].append((c, b0))
        g[a1].append((c, b1))
        g[b0].append((c, a0))
        g[b1].append((c, a1))
    else:
        g[a1].append((c, b0))
        g[a1].append((c, b1))
        g[b1].append((c, a0))
        g[b1].append((c, a1))

dist, _ = dijkstra(2*n-1, g)
for i in range(n-1):
    print(dist[i])
0