結果

問題 No.807 umg tours
ユーザー tempura_pptempura_pp
提出日時 2019-03-17 01:35:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 690 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 10,708 KB
実行使用メモリ 182,744 KB
最終ジャッジ日時 2023-09-18 09:27:41
合計ジャッジ時間 39,326 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,416 KB
testcase_01 AC 19 ms
8,432 KB
testcase_02 AC 22 ms
8,636 KB
testcase_03 AC 22 ms
8,504 KB
testcase_04 AC 19 ms
8,404 KB
testcase_05 AC 20 ms
8,584 KB
testcase_06 AC 22 ms
8,504 KB
testcase_07 AC 21 ms
8,492 KB
testcase_08 AC 17 ms
8,248 KB
testcase_09 AC 18 ms
8,440 KB
testcase_10 AC 18 ms
8,240 KB
testcase_11 AC 2,593 ms
134,208 KB
testcase_12 AC 2,218 ms
104,960 KB
testcase_13 AC 3,217 ms
144,160 KB
testcase_14 AC 1,252 ms
68,100 KB
testcase_15 AC 956 ms
55,160 KB
testcase_16 AC 3,290 ms
151,428 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 AC 3,881 ms
170,388 KB
testcase_20 AC 1,823 ms
95,704 KB
testcase_21 AC 1,912 ms
99,232 KB
testcase_22 AC 767 ms
47,644 KB
testcase_23 AC 579 ms
39,224 KB
testcase_24 AC 1,966 ms
135,968 KB
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

N, M = map(int, input().split())

edge = [[] for i in range(2*N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a-=1
    b-=1
    edge[a].append((c, b))
    edge[b].append((c, a))
    edge[a+N].append((c, b+N))
    edge[b+N].append((c, a+N))
    edge[a].append((0, b+N))
    edge[b].append((0, a+N))

dist=[float('inf')]*(2*N)
dist[0]=dist[N]=0

pq = []
heappush(pq, (0,0))
heappush(pq, (0,N))
while pq:
    d, cur = heappop(pq)
    if d > dist[cur]: continue

    for cost, to in edge[cur]:
        if dist[to]>d+cost : 
            dist[to]=d+cost
            heappush(pq, (d+cost,to))
for i in range(N) :
    print(dist[i]+dist[i+N])
0