結果

問題 No.1607 Kth Maximum Card
ユーザー NoneNone
提出日時 2021-10-04 09:37:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,250 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 81,132 KB
最終ジャッジ日時 2023-09-29 14:49:04
合計ジャッジ時間 6,775 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,172 KB
testcase_01 AC 71 ms
71,432 KB
testcase_02 AC 71 ms
71,336 KB
testcase_03 AC 71 ms
71,476 KB
testcase_04 AC 71 ms
71,172 KB
testcase_05 AC 72 ms
71,104 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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