結果

問題 No.1473 おでぶなおばけさん
ユーザー aqua_tenhou
提出日時 2022-01-04 19:17:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 139,036 KB
最終ジャッジ日時 2024-10-14 15:01:30
合計ジャッジ時間 20,500 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def is_ok(arg):
    p = l[arg]
    w = BWS(p)
    return w != 10**18

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def BWS(w):
    q = deque([])
    reach = [10**18]*(n+1)

    q.append(1)
    reach[1] = 0
    while q:
        x = q.popleft()
        for y,z in V[x]:
            if reach[y] > reach[x] + 1 and w <= z:
                q.append(y)
                reach[y] = reach[x] + 1
    return reach[-1]

n,m = map(int,input().split())
z = [list(map(int,input().split())) for i in range(m)]
V = [[] for i in range(n+1)]
se = set([])
for s,t,d in z:
    V[s].append([t,d])
    V[t].append([s,d])
    se.add(d)

l = list(se)
l = [0] + sorted(l) + [10**18]
M = len(l)
ans = meguru_bisect(M, 0)
print(l[ans], BWS(l[ans]))
0