結果

問題 No.1473 おでぶなおばけさん
ユーザー Eki1009Eki1009
提出日時 2021-04-09 21:44:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 657 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 113,328 KB
最終ジャッジ日時 2023-09-07 10:39:15
合計ジャッジ時間 22,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,236 KB
testcase_01 AC 76 ms
71,208 KB
testcase_02 AC 657 ms
111,792 KB
testcase_03 AC 540 ms
105,316 KB
testcase_04 AC 427 ms
96,668 KB
testcase_05 AC 300 ms
85,492 KB
testcase_06 AC 596 ms
105,528 KB
testcase_07 AC 598 ms
113,052 KB
testcase_08 AC 649 ms
113,328 KB
testcase_09 AC 601 ms
113,280 KB
testcase_10 AC 254 ms
88,092 KB
testcase_11 AC 239 ms
87,440 KB
testcase_12 AC 256 ms
88,352 KB
testcase_13 AC 177 ms
81,544 KB
testcase_14 AC 157 ms
79,436 KB
testcase_15 AC 198 ms
84,172 KB
testcase_16 AC 238 ms
85,808 KB
testcase_17 AC 137 ms
77,684 KB
testcase_18 AC 143 ms
78,036 KB
testcase_19 AC 415 ms
90,268 KB
testcase_20 AC 509 ms
102,456 KB
testcase_21 AC 526 ms
96,636 KB
testcase_22 AC 545 ms
107,724 KB
testcase_23 AC 521 ms
105,068 KB
testcase_24 AC 485 ms
102,180 KB
testcase_25 AC 539 ms
107,280 KB
testcase_26 AC 549 ms
106,248 KB
testcase_27 AC 268 ms
86,952 KB
testcase_28 AC 592 ms
112,684 KB
testcase_29 AC 550 ms
96,928 KB
testcase_30 AC 584 ms
99,564 KB
testcase_31 AC 646 ms
113,044 KB
testcase_32 AC 608 ms
107,284 KB
testcase_33 AC 555 ms
101,336 KB
testcase_34 AC 390 ms
91,088 KB
testcase_35 AC 391 ms
90,132 KB
testcase_36 AC 389 ms
95,900 KB
testcase_37 AC 482 ms
103,028 KB
testcase_38 AC 229 ms
82,828 KB
testcase_39 AC 234 ms
85,848 KB
testcase_40 AC 236 ms
85,960 KB
testcase_41 AC 182 ms
89,176 KB
testcase_42 AC 187 ms
89,084 KB
testcase_43 AC 416 ms
110,316 KB
testcase_44 AC 413 ms
110,628 KB
testcase_45 AC 418 ms
110,616 KB
testcase_46 AC 288 ms
98,424 KB
testcase_47 AC 330 ms
103,976 KB
testcase_48 AC 316 ms
97,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def dijkstra(G, start=0):
    n = len(G)
    dist = [-1] * n
    Q = []
    dist[start] = 0
    heapq.heappush(Q, (0, start))
    while Q:
        p = heapq.heappop(Q)
        v = p[1]
        d = dist[v]
        if d < p[0]:
            continue
        for nv, nc in G[v]:
            if dist[nv] == -1 or d + nc < dist[nv]:
                dist[nv] = d + nc
                heapq.heappush(Q, (d + nc, nv))
    return dist

def dijkstra_max(G, start=0):
    inf = 10**10
    n = len(G)
    dist = [-1] * n
    Q = []
    dist[start] = inf
    heapq.heappush(Q, (-inf, start))
    while Q:
        p = heapq.heappop(Q)
        v = p[1]
        d = dist[v]
        if d < p[0]:
            continue
        for nv, nc in G[v]:
            if dist[nv] == -1 or min(d, nc) > dist[nv]:
                dist[nv] = min(d, nc)
                heapq.heappush(Q, (-min(d, nc), nv))
    return dist

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    s, t, d = map(int, input().split())
    s -= 1
    t -= 1
    G[s].append((t, d))
    G[t].append((s, d))
L = dijkstra_max(G)
w = L[n-1]
T = [[] for _ in range(n)]
for v, g in enumerate(G):
    for nv, d in g:
        if w <= d:
            T[v].append((nv, 1))
ans = dijkstra(T)[n-1]
print(w, ans)
0