結果

問題 No.1601 With Animals into Institute
ユーザー rlangevinrlangevin
提出日時 2023-02-25 19:38:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,400 ms / 3,000 ms
コード長 1,381 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 86,408 KB
実行使用メモリ 144,900 KB
最終ジャッジ日時 2023-10-11 16:14:51
合計ジャッジ時間 25,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,152 KB
testcase_01 AC 80 ms
71,264 KB
testcase_02 AC 80 ms
71,528 KB
testcase_03 AC 191 ms
79,760 KB
testcase_04 AC 167 ms
79,696 KB
testcase_05 AC 172 ms
79,764 KB
testcase_06 AC 1,275 ms
143,396 KB
testcase_07 AC 1,400 ms
143,624 KB
testcase_08 AC 1,303 ms
144,256 KB
testcase_09 AC 1,255 ms
141,844 KB
testcase_10 AC 1,250 ms
144,852 KB
testcase_11 AC 1,295 ms
140,784 KB
testcase_12 AC 1,256 ms
140,240 KB
testcase_13 AC 1,329 ms
144,900 KB
testcase_14 AC 1,295 ms
141,576 KB
testcase_15 AC 1,304 ms
142,712 KB
testcase_16 AC 1,309 ms
142,456 KB
testcase_17 AC 1,282 ms
141,448 KB
testcase_18 AC 173 ms
79,516 KB
testcase_19 AC 172 ms
79,556 KB
testcase_20 AC 167 ms
79,344 KB
testcase_21 AC 165 ms
79,368 KB
testcase_22 AC 164 ms
79,280 KB
testcase_23 AC 169 ms
79,452 KB
testcase_24 AC 174 ms
79,224 KB
testcase_25 AC 163 ms
79,360 KB
testcase_26 AC 167 ms
79,608 KB
testcase_27 AC 79 ms
71,140 KB
testcase_28 AC 78 ms
71,280 KB
testcase_29 AC 80 ms
71,304 KB
testcase_30 AC 80 ms
71,364 KB
testcase_31 AC 79 ms
71,304 KB
testcase_32 AC 80 ms
71,024 KB
testcase_33 AC 80 ms
71,444 KB
testcase_34 AC 81 ms
71,320 KB
testcase_35 AC 81 ms
71,448 KB
testcase_36 AC 80 ms
71,348 KB
testcase_37 AC 83 ms
71,168 KB
testcase_38 AC 81 ms
71,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from heapq import heappush, heappop
inf = float('inf')


def dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
    return dist


N, M = map(int, readline().split())
G = [[] for i in range(2 * N)]
for i in range(M):
    A, B, C, X = map(int, readline().split())
    A, B = A - 1, B - 1
    if X:
        G[A].append((B + N, C))
        G[B].append((A + N, C))
        G[A + N].append((B + N, C))
        G[B + N].append((A + N, C))
    else:
        G[A].append((B, C))
        G[B].append((A, C))
        G[A + N].append((B + N, C))
        G[B + N].append((A + N, C))
        
D = dijkstra(N - 1, -1, 2 * N)
for i in range(N - 1):
    print(D[i + N])
0