結果

問題 No.1473 おでぶなおばけさん
ユーザー ygd.
提出日時 2021-04-10 16:23:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,092 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 125,212 KB
最終ジャッジ日時 2024-06-26 05:35:40
合計ジャッジ時間 19,510 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n,m = map(int,input().split()); INF = float("inf")
G = [[] for _ in range(n)]
for i in range(m):
    s,t,d = map(int,input().split())
    s-=1;t-=1
    G[s].append((t,d))
    G[t].append((s,d))

def BFS(w):
    D = [INF]*n
    D[0] = 0
    Q = deque([])
    Q.append(0)
    while Q:
        v = Q.popleft()
        for u,d in G[v]:
            if d < w: continue
            if D[u] <= D[v] + 1: continue
            D[u] = D[v] + 1
            Q.append(u)
    return D
            
    
ok = 1
ng = pow(10,9) + 1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    dis = BFS(mid)
    #print(dis,mid)
    if dis[n-1] < INF:
        ok = mid
    else:
        ng = mid
dis = BFS(ok)
ans = [ok,dis[n-1]]
print(*ans)
0