結果

問題 No.807 umg tours
ユーザー 👑 KazunKazun
提出日時 2021-03-02 18:26:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,626 ms / 4,000 ms
コード長 737 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 194,264 KB
最終ジャッジ日時 2024-04-14 04:47:23
合計ジャッジ時間 18,264 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
61,668 KB
testcase_01 AC 56 ms
63,212 KB
testcase_02 AC 65 ms
64,968 KB
testcase_03 AC 63 ms
64,328 KB
testcase_04 AC 57 ms
61,616 KB
testcase_05 AC 56 ms
61,052 KB
testcase_06 AC 61 ms
62,604 KB
testcase_07 AC 61 ms
64,404 KB
testcase_08 AC 47 ms
53,128 KB
testcase_09 AC 47 ms
53,880 KB
testcase_10 AC 48 ms
54,244 KB
testcase_11 AC 1,040 ms
142,708 KB
testcase_12 AC 991 ms
143,108 KB
testcase_13 AC 1,230 ms
162,748 KB
testcase_14 AC 651 ms
115,784 KB
testcase_15 AC 499 ms
105,872 KB
testcase_16 AC 1,302 ms
169,240 KB
testcase_17 AC 1,563 ms
190,896 KB
testcase_18 AC 1,602 ms
190,176 KB
testcase_19 AC 1,521 ms
188,716 KB
testcase_20 AC 840 ms
149,404 KB
testcase_21 AC 915 ms
154,212 KB
testcase_22 AC 417 ms
105,464 KB
testcase_23 AC 385 ms
100,772 KB
testcase_24 AC 698 ms
175,496 KB
testcase_25 AC 1,626 ms
194,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heapify,heappop,heappush
input=sys.stdin.readline
write=sys.stdout.write

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

for _ in range(M):
    a,b,c=map(int,input().split())
    E[a].append((b,c))
    E[a].append((b+N,c))
    E[a+N].append((b+N,c))

    E[b].append((a,c))
    E[b].append((a+N,c))
    E[b+N].append((a+N,c))

inf=float("inf")
T=[inf]*(2*N+1)
T[1]=0

S=set()

Q=[(0,1)]

while Q and len(S)<2*N:
    d,x=heappop(Q)
    if x in S:
        continue

    S.add(x)
    for y,c in E[x]:
        if x<=N and N<y:
            c=0

        if T[y]>d+c:
            T[y]=d+c
            heappush(Q,(d+c,y))

X=[T[x]+T[x+N] if x!=1 else 0 for x in range(1,N+1)]
write("\n".join(map(str,X)))
0