結果

問題 No.1601 With Animals into Institute
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-23 19:59:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,073 ms / 3,000 ms
コード長 1,154 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 143,176 KB
最終ジャッジ日時 2023-08-07 18:26:21
合計ジャッジ時間 20,110 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,496 KB
testcase_01 AC 74 ms
71,496 KB
testcase_02 AC 73 ms
71,128 KB
testcase_03 AC 140 ms
79,700 KB
testcase_04 AC 136 ms
79,192 KB
testcase_05 AC 148 ms
79,056 KB
testcase_06 AC 959 ms
142,388 KB
testcase_07 AC 971 ms
143,176 KB
testcase_08 AC 944 ms
143,060 KB
testcase_09 AC 1,072 ms
142,656 KB
testcase_10 AC 1,073 ms
142,800 KB
testcase_11 AC 1,008 ms
141,928 KB
testcase_12 AC 995 ms
141,452 KB
testcase_13 AC 1,032 ms
142,616 KB
testcase_14 AC 993 ms
141,904 KB
testcase_15 AC 1,046 ms
142,616 KB
testcase_16 AC 1,035 ms
141,968 KB
testcase_17 AC 1,038 ms
141,976 KB
testcase_18 AC 149 ms
79,404 KB
testcase_19 AC 145 ms
79,228 KB
testcase_20 AC 147 ms
79,440 KB
testcase_21 AC 145 ms
79,436 KB
testcase_22 AC 146 ms
78,956 KB
testcase_23 AC 142 ms
78,844 KB
testcase_24 AC 143 ms
79,332 KB
testcase_25 AC 150 ms
79,120 KB
testcase_26 AC 145 ms
79,108 KB
testcase_27 AC 76 ms
71,124 KB
testcase_28 AC 75 ms
71,324 KB
testcase_29 AC 75 ms
71,148 KB
testcase_30 AC 75 ms
71,140 KB
testcase_31 AC 75 ms
71,496 KB
testcase_32 AC 75 ms
71,452 KB
testcase_33 AC 74 ms
71,304 KB
testcase_34 AC 76 ms
71,584 KB
testcase_35 AC 74 ms
71,284 KB
testcase_36 AC 75 ms
71,336 KB
testcase_37 AC 75 ms
71,360 KB
testcase_38 AC 75 ms
71,416 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