結果

問題 No.1473 おでぶなおばけさん
ユーザー titia
提出日時 2022-02-11 02:29:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 741 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 112,900 KB
最終ジャッジ日時 2024-06-26 10:20:12
合計ジャッジ時間 15,436 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import deque

n,m=map(int,input().split())
E=[[] for i in range(n+1)]

for i in range(m):
    s,t,d=map(int,input().split())
    E[s].append((t,d))
    E[t].append((s,d))


OK=1
NG=1<<31

while NG-OK>1:
    mid=(OK+NG)//2

    GO=[0]*(n+1)
    GO[1]=1
    Q=[1]

    while Q:
        x=Q.pop()
        for to,d in E[x]:
            if d>=mid and GO[to]==0:
                GO[to]=1
                Q.append(to)

    if GO[n]==1:
        OK=mid
    else:
        NG=mid

X=[-1]*(n+1)
X[1]=0
Q=deque([1])

while Q:
    x=Q.popleft()
    
    for to,d in E[x]:
        if d>=OK and X[to]==-1:
            X[to]=X[x]+1
            Q.append(to)

print(OK,X[n])
                
0