結果

問題 No.807 umg tours
ユーザー kohei2019kohei2019
提出日時 2022-04-14 01:05:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,154 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 140,224 KB
最終ジャッジ日時 2023-08-25 17:35:42
合計ジャッジ時間 26,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
76,384 KB
testcase_01 AC 97 ms
76,668 KB
testcase_02 AC 100 ms
76,372 KB
testcase_03 AC 97 ms
76,092 KB
testcase_04 AC 88 ms
76,272 KB
testcase_05 AC 90 ms
76,352 KB
testcase_06 AC 97 ms
76,440 KB
testcase_07 AC 95 ms
76,364 KB
testcase_08 AC 76 ms
71,156 KB
testcase_09 AC 77 ms
71,380 KB
testcase_10 AC 79 ms
71,204 KB
testcase_11 AC 1,123 ms
112,328 KB
testcase_12 AC 1,307 ms
115,164 KB
testcase_13 AC 1,607 ms
124,840 KB
testcase_14 AC 775 ms
100,428 KB
testcase_15 AC 580 ms
94,136 KB
testcase_16 AC 1,444 ms
125,444 KB
testcase_17 AC 2,294 ms
140,224 KB
testcase_18 AC 2,243 ms
139,596 KB
testcase_19 AC 1,946 ms
134,496 KB
testcase_20 AC 932 ms
113,276 KB
testcase_21 AC 978 ms
116,808 KB
testcase_22 AC 471 ms
92,480 KB
testcase_23 AC 429 ms
91,180 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N,M = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    lsg[a].append((b,c))
    lsg[b].append((a,c))

h = [(0,0,0)]
INF = float('INF')
cost0 = [INF]*(N)
cost1 = [INF]*(N)
cost0[0] = 0
cost1[0] = 0
used0 = [False]*(N)
used1 = [False]*(N)
while h:
    c,n,f = heapq.heappop(h)
    if used0[n] and used1[n]:
        continue
    if f == 0:
        used0[n] = True
    if f == 1:
        used1[n] = True
    for nex,cos in lsg[n]:
        if f == 0: # 使える
            if used0[nex]==False:
                if cost0[nex] > c + cos: # 使わない
                    cost0[nex] = c + cos
                    heapq.heappush(h, (c+cos,nex,0))
            if used1[nex]==False:
                if cost1[nex] > c: # 使う
                    cost1[nex] = c
                    heapq.heappush(h, (c,nex,1))
        if f == 1: # 使えない
            if used1[nex]==False:
                if cost1[nex] > c+ cos:
                    cost1[nex] = c+ cos
                    heapq.heappush(h, (c+ cos,nex,1))

for i in range(N):
    print(cost0[i]+cost1[i])
0