結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
lie_of_lillie
|
| 提出日時 | 2021-05-14 15:38:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,241 bytes |
| コンパイル時間 | 309 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 59,676 KB |
| 最終ジャッジ日時 | 2024-10-01 20:14:01 |
| 合計ジャッジ時間 | 6,555 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 46 |
ソースコード
import collections
import heapq
import math
N,M=map(int,input().split())
G = collections.defaultdict(list)
for _ in range(M):
S,T,D = map(int, input().split())
G[S-1].append((T-1,D))
G[T-1].append((S-1,D))
def dijkstra():
weights = [-math.inf for _ in range(N)]
que = []
heapq.heapify(que)
heapq.heappush(que, (math.inf, 0)) # weight, index
nums = [0]*N
while que:
'''
aw: accumlated weight
nw: next weight
'''
aw, i = heapq.heappop(que)
if weights[i] and aw <= weights[i]:
continue
weights[i] = aw
for j, nw in G[i]:
nw = min(aw, nw)
heapq.heappush(que, (nw, j))
ans = weights[N-1]
return ans
def bfs(max_w):
que = collections.deque([(0,0)]) # index, something val
visited = [-1]*N
while que:
i, c = que.popleft() # queはFIFO
if visited[i] >= 0:
continue
visited[i] = c
for j, d in G[i]:
if visited[j] == -1 and max_w <= d: # まだ未踏のノードであれば
que.append((j,c+1)) # 自分の値に+1してqueに入れる
return visited[-1]
max_w = dijkstra()
min_p = bfs(max_w)
print(max_w, min_p)
lie_of_lillie