結果

問題 No.807 umg tours
ユーザー 👑 KazunKazun
提出日時 2021-03-02 18:20:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,376 ms / 4,000 ms
コード長 699 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 166,768 KB
最終ジャッジ日時 2024-04-14 04:46:21
合計ジャッジ時間 16,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
62,636 KB
testcase_01 AC 51 ms
63,720 KB
testcase_02 AC 53 ms
64,716 KB
testcase_03 AC 52 ms
64,584 KB
testcase_04 AC 48 ms
63,336 KB
testcase_05 AC 47 ms
62,496 KB
testcase_06 AC 55 ms
66,104 KB
testcase_07 AC 52 ms
64,040 KB
testcase_08 AC 38 ms
53,052 KB
testcase_09 AC 40 ms
53,828 KB
testcase_10 AC 39 ms
54,016 KB
testcase_11 AC 802 ms
138,064 KB
testcase_12 AC 825 ms
126,524 KB
testcase_13 AC 1,076 ms
146,476 KB
testcase_14 AC 511 ms
106,040 KB
testcase_15 AC 402 ms
99,360 KB
testcase_16 AC 1,112 ms
150,140 KB
testcase_17 AC 1,347 ms
163,464 KB
testcase_18 AC 1,354 ms
163,636 KB
testcase_19 AC 1,241 ms
160,968 KB
testcase_20 AC 709 ms
125,600 KB
testcase_21 AC 727 ms
129,172 KB
testcase_22 AC 338 ms
98,288 KB
testcase_23 AC 318 ms
94,532 KB
testcase_24 AC 610 ms
151,948 KB
testcase_25 AC 1,376 ms
166,768 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]=T[N+1]=0
Q=[(0,1),(0,N+1)]

while Q:
    d,x=heappop(Q)
    if T[x]<d:
        continue

    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] for x in range(1,N+1)]
write("\n".join(map(str,X)))
0