結果

問題 No.807 umg tours
ユーザー ntudantuda
提出日時 2021-12-02 20:12:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,229 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 173,012 KB
最終ジャッジ日時 2023-09-18 10:29:40
合計ジャッジ時間 26,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
75,744 KB
testcase_01 AC 95 ms
75,960 KB
testcase_02 AC 106 ms
76,124 KB
testcase_03 AC 105 ms
76,316 KB
testcase_04 AC 87 ms
71,132 KB
testcase_05 AC 95 ms
76,276 KB
testcase_06 AC 104 ms
76,188 KB
testcase_07 AC 103 ms
76,344 KB
testcase_08 AC 82 ms
71,144 KB
testcase_09 AC 86 ms
71,296 KB
testcase_10 AC 84 ms
71,164 KB
testcase_11 AC 1,273 ms
144,644 KB
testcase_12 AC 1,259 ms
133,116 KB
testcase_13 AC 1,680 ms
153,860 KB
testcase_14 AC 763 ms
110,912 KB
testcase_15 AC 647 ms
105,644 KB
testcase_16 AC 1,839 ms
161,272 KB
testcase_17 AC 2,062 ms
173,012 KB
testcase_18 AC 2,080 ms
172,876 KB
testcase_19 AC 2,173 ms
172,600 KB
testcase_20 AC 1,038 ms
128,536 KB
testcase_21 AC 1,117 ms
134,320 KB
testcase_22 AC 541 ms
99,580 KB
testcase_23 AC 489 ms
96,808 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
E = [[] for _ in range(N)]
for a,b,c in ABC:
    E[a-1].append([b-1,c])
    E[b-1].append([a-1,c])
import heapq
D = [float('inf')] * N
D2 = [float('inf')] * N

#普通のダイクストラ
def dijkstra():
    D[0] = 0
    q = []
    heapq.heappush(q, [0, 0])
    while len(q) > 0:
        # ヒープから取り出し
        _, u = heapq.heappop(q)
        for i in E[u]:
            a,b = i
            if D[a] > D[u] + b:
                # 頂点までのコストが更新できれば更新してヒープに登録
                D[a] = D[u] + b
                heapq.heappush(q, [D[a], a])
    return D

#コスト-最大値の最小を取っていくダイクストラ
def dijkstra2():
    D2[0] = 0
    q = []
    heapq.heappush(q, [0, 0]) #コスト、頂点
    while len(q) > 0:
        # ヒープから取り出し
        _, u = heapq.heappop(q)
        for i in E[u]:
            a,b = i
            tmp = min(D[u],D2[u] + b)
            if D2[a] > tmp:
                D2[a] = tmp
                heapq.heappush(q, [D2[a], a])

    return D2

dijkstra()
dijkstra2()
ans = [0] * N
for i in range(N):
    print(D[i] + D2[i])
0