結果

問題 No.1473 おでぶなおばけさん
ユーザー hiragnhiragn
提出日時 2022-12-04 01:13:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 821 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 108,440 KB
最終ジャッジ日時 2024-04-19 11:22:56
合計ジャッジ時間 16,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,760 KB
testcase_01 AC 45 ms
53,760 KB
testcase_02 AC 537 ms
105,132 KB
testcase_03 AC 717 ms
105,304 KB
testcase_04 AC 240 ms
90,432 KB
testcase_05 AC 177 ms
82,004 KB
testcase_06 AC 821 ms
108,440 KB
testcase_07 AC 338 ms
99,156 KB
testcase_08 AC 338 ms
99,304 KB
testcase_09 AC 315 ms
99,304 KB
testcase_10 AC 181 ms
86,528 KB
testcase_11 AC 172 ms
83,968 KB
testcase_12 AC 179 ms
84,224 KB
testcase_13 AC 133 ms
81,144 KB
testcase_14 AC 109 ms
78,848 KB
testcase_15 AC 149 ms
83,584 KB
testcase_16 AC 159 ms
83,200 KB
testcase_17 AC 84 ms
77,440 KB
testcase_18 AC 91 ms
77,312 KB
testcase_19 AC 314 ms
87,804 KB
testcase_20 AC 592 ms
101,512 KB
testcase_21 AC 369 ms
92,088 KB
testcase_22 AC 283 ms
93,684 KB
testcase_23 AC 247 ms
93,992 KB
testcase_24 AC 262 ms
91,856 KB
testcase_25 AC 268 ms
93,160 KB
testcase_26 AC 286 ms
94,024 KB
testcase_27 AC 147 ms
80,512 KB
testcase_28 AC 374 ms
102,180 KB
testcase_29 AC 437 ms
92,516 KB
testcase_30 AC 589 ms
99,648 KB
testcase_31 AC 384 ms
101,892 KB
testcase_32 AC 817 ms
108,392 KB
testcase_33 AC 494 ms
97,412 KB
testcase_34 AC 247 ms
85,460 KB
testcase_35 AC 253 ms
85,888 KB
testcase_36 AC 225 ms
86,780 KB
testcase_37 AC 245 ms
93,568 KB
testcase_38 AC 107 ms
77,952 KB
testcase_39 AC 159 ms
83,200 KB
testcase_40 AC 160 ms
83,228 KB
testcase_41 AC 148 ms
87,552 KB
testcase_42 AC 148 ms
87,616 KB
testcase_43 AC 195 ms
95,944 KB
testcase_44 AC 199 ms
95,688 KB
testcase_45 AC 191 ms
95,812 KB
testcase_46 AC 224 ms
91,216 KB
testcase_47 AC 252 ms
92,652 KB
testcase_48 AC 240 ms
92,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
https://qiita.com/c-yan/items/1ad8c9d5400077f19459#e-1473-%E3%81%8A%E3%81%A7%E3%81%B6%E3%81%AA%E3%81%8A%E3%81%B0%E3%81%91%E3%81%95%E3%82%93

c-yanさんのqiita記事の変数名をいじっただけ。
"""
from collections import defaultdict, deque


def main():
    n, m = map(int, input().split())

    adj = defaultdict(list)
    for _ in range(m):
        s, t, d = map(int, input().split())
        s -= 1
        t -= 1
        adj[s].append((t, d))
        adj[t].append((s, d))

    q = deque([(0, 10 ** 15)])
    # (都市iに到達可能な体重wのmax)
    # = (その経路のdのmin)
    # dp[i]:(都市iまでの経路のdのmin, 対応するパス長)
    dp = [(-1, -1) for _ in range(n)]
    dp[0] = (10 ** 15, 0)
    while q:
        cur_city, cur_d = q.popleft()
        if dp[cur_city][0] > cur_d:
            continue
        for nxt_city, nxt_d in adj[cur_city]:
            new_d = min(cur_d, nxt_d)
            if dp[nxt_city][0] >= new_d:
                continue
            if dp[nxt_city][0] == new_d:
                dp[nxt_city] = (new_d, min(dp[nxt_city][1], dp[cur_city][1] + 1))
            else:
                dp[nxt_city] = (new_d, dp[cur_city][1] + 1)
            q.append((nxt_city, new_d))
    print(*dp[n - 1])


if __name__ == "__main__":
    main()
0