結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
hiragn
|
| 提出日時 | 2022-12-04 01:13:00 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,298 bytes |
| コンパイル時間 | 105 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 57,116 KB |
| 最終ジャッジ日時 | 2024-10-11 03:35:55 |
| 合計ジャッジ時間 | 38,045 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 TLE * 1 |
ソースコード
"""
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()
hiragn