結果

問題 No.807 umg tours
ユーザー 👑 KazunKazun
提出日時 2021-03-02 18:22:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,375 ms / 4,000 ms
コード長 699 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 168,712 KB
最終ジャッジ日時 2023-07-26 14:49:56
合計ジャッジ時間 17,001 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
76,036 KB
testcase_01 AC 88 ms
75,920 KB
testcase_02 AC 92 ms
75,996 KB
testcase_03 AC 91 ms
76,004 KB
testcase_04 AC 89 ms
75,960 KB
testcase_05 AC 88 ms
76,152 KB
testcase_06 AC 91 ms
75,956 KB
testcase_07 AC 91 ms
75,880 KB
testcase_08 AC 79 ms
71,364 KB
testcase_09 AC 80 ms
71,348 KB
testcase_10 AC 80 ms
71,232 KB
testcase_11 AC 891 ms
138,680 KB
testcase_12 AC 843 ms
128,376 KB
testcase_13 AC 1,046 ms
146,636 KB
testcase_14 AC 586 ms
107,840 KB
testcase_15 AC 466 ms
101,284 KB
testcase_16 AC 1,098 ms
151,236 KB
testcase_17 AC 1,307 ms
164,576 KB
testcase_18 AC 1,308 ms
165,428 KB
testcase_19 AC 1,300 ms
162,772 KB
testcase_20 AC 720 ms
126,872 KB
testcase_21 AC 764 ms
131,156 KB
testcase_22 AC 389 ms
99,480 KB
testcase_23 AC 359 ms
95,876 KB
testcase_24 AC 627 ms
152,152 KB
testcase_25 AC 1,375 ms
168,712 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
Q=[(0,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] if x!=1 else 0 for x in range(1,N+1)]
write("\n".join(map(str,X)))
0