結果

問題 No.1607 Kth Maximum Card
ユーザー NoneNone
提出日時 2021-10-04 09:38:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,479 ms / 3,500 ms
コード長 1,250 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 287,632 KB
最終ジャッジ日時 2023-09-29 14:50:40
合計ジャッジ時間 30,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,244 KB
testcase_01 AC 69 ms
71,316 KB
testcase_02 AC 69 ms
71,480 KB
testcase_03 AC 69 ms
71,348 KB
testcase_04 AC 69 ms
71,140 KB
testcase_05 AC 70 ms
71,424 KB
testcase_06 AC 69 ms
71,236 KB
testcase_07 AC 69 ms
71,356 KB
testcase_08 AC 2,293 ms
261,544 KB
testcase_09 AC 1,986 ms
224,096 KB
testcase_10 AC 2,479 ms
259,584 KB
testcase_11 AC 432 ms
100,516 KB
testcase_12 AC 1,802 ms
217,840 KB
testcase_13 AC 244 ms
88,288 KB
testcase_14 AC 365 ms
98,032 KB
testcase_15 AC 1,129 ms
190,856 KB
testcase_16 AC 251 ms
91,272 KB
testcase_17 AC 154 ms
79,892 KB
testcase_18 AC 831 ms
157,104 KB
testcase_19 AC 485 ms
114,364 KB
testcase_20 AC 590 ms
112,184 KB
testcase_21 AC 686 ms
128,396 KB
testcase_22 AC 2,171 ms
287,632 KB
testcase_23 AC 2,129 ms
281,672 KB
testcase_24 AC 632 ms
120,888 KB
testcase_25 AC 335 ms
94,076 KB
testcase_26 AC 446 ms
105,196 KB
testcase_27 AC 658 ms
120,344 KB
testcase_28 AC 529 ms
108,468 KB
testcase_29 AC 1,388 ms
195,016 KB
testcase_30 AC 2,355 ms
237,392 KB
testcase_31 AC 1,248 ms
164,720 KB
testcase_32 AC 348 ms
97,916 KB
testcase_33 AC 345 ms
98,184 KB
testcase_34 AC 328 ms
98,224 KB
testcase_35 AC 340 ms
98,000 KB
権限があれば一括ダウンロードができます

ソースコード

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