結果

問題 No.1607 Kth Maximum Card
ユーザー None
提出日時 2021-10-04 09:38:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,564 ms / 3,500 ms
コード長 1,250 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 301,580 KB
最終ジャッジ日時 2024-07-22 09:01:44
合計ジャッジ時間 30,007 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

def binary_search_int(ok,ng,test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if test(mid):
            ok=mid
        else:
            ng=mid
    return ok


##############################################################
import sys
input = sys.stdin.readline

INF = 10**18  # 大きい数字

N, M, K = map(int, input().split())


edges=[[] for _ in range(N)]
for _ in range(M):
    x, y, cost = map(int, input().split())
    x-=1
    y-=1
    edges[x].append((y,cost))
    edges[y].append((x,cost))


def test(k):
    next_set=[[] for _ in range(N)]
    next_set[0]=[0]
    dist=[INF]*(N+1)
    for time in range(N):
        while next_set[time]:
            p = next_set[time].pop()
            if dist[p]<time: continue
            for q,d in edges[p]:
                if d>k:
                    cost=1
                else:
                    cost=0
                if dist[q]<=time+cost:
                    continue
                dist[q]=time+cost
                if q!=N-1:
                    next_set[time+cost].append(q)

    return dist[N-1]<=K-1

kmin=binary_search_int(10**6,-1,test)

print(kmin)
0