結果

問題 No.1473 おでぶなおばけさん
ユーザー kohei2019
提出日時 2022-05-21 19:25:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 881 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 208,640 KB
最終ジャッジ日時 2024-09-20 12:05:59
合計ジャッジ時間 22,307 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N,M = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(M):
    s,t,d = map(int,input().split())
    s -= 1
    t -= 1
    lsg[s].append((t,d))
    lsg[t].append((s,d))
INF = float('INF')
def is_ok(arg):
    d = collections.deque([0])
    used = [False]*(N)
    cost = [INF]*N
    cost[0] = 0
    while d:
        x = d.popleft()
        if used[x]:
            continue
        used[x] = True
        for y,c in lsg[x]:
            if used[y]:
                continue
            if (cost[y] > cost[x] + 1) and (arg <= c):
                cost[y] = cost[x] + 1
                d.append(y)
    return used[N-1]
 
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
w = meguru_bisect(10**18+1,0)
d = collections.deque([0])
used = [False]*(N)
cost = [INF]*N
cost[0] = 0
while d:
    x = d.popleft()
    if used[x]:
        continue
    used[x] = True
    for y,c in lsg[x]:
        if used[y]:
            continue
        if (cost[y] > cost[x] + 1) and (w <= c):
            cost[y] = cost[x] + 1
            d.append(y)

print(w,cost[N-1])
0