結果

問題 No.807 umg tours
ユーザー 👑 KazunKazun
提出日時 2021-03-02 18:24:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,408 ms / 4,000 ms
コード長 724 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 169,820 KB
最終ジャッジ日時 2024-04-14 04:46:58
合計ジャッジ時間 16,342 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
62,280 KB
testcase_01 AC 50 ms
62,856 KB
testcase_02 AC 55 ms
65,108 KB
testcase_03 AC 52 ms
64,800 KB
testcase_04 AC 48 ms
62,464 KB
testcase_05 AC 48 ms
62,368 KB
testcase_06 AC 52 ms
64,236 KB
testcase_07 AC 51 ms
63,652 KB
testcase_08 AC 40 ms
53,504 KB
testcase_09 AC 40 ms
53,912 KB
testcase_10 AC 39 ms
54,004 KB
testcase_11 AC 835 ms
137,780 KB
testcase_12 AC 850 ms
126,996 KB
testcase_13 AC 1,071 ms
146,984 KB
testcase_14 AC 571 ms
107,816 KB
testcase_15 AC 434 ms
100,628 KB
testcase_16 AC 1,145 ms
151,684 KB
testcase_17 AC 1,384 ms
164,740 KB
testcase_18 AC 1,378 ms
164,688 KB
testcase_19 AC 1,341 ms
162,256 KB
testcase_20 AC 732 ms
127,312 KB
testcase_21 AC 790 ms
130,740 KB
testcase_22 AC 367 ms
99,228 KB
testcase_23 AC 339 ms
95,052 KB
testcase_24 AC 609 ms
155,180 KB
testcase_25 AC 1,408 ms
169,820 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=[0]*(2*N+1)

Q=[(0,1)]

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

    S[x]=1
    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