結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 KazunKazun
提出日時 2021-07-17 00:08:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,861 ms / 3,500 ms
コード長 1,305 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 211,624 KB
最終ジャッジ日時 2023-09-20 16:38:54
合計ジャッジ時間 27,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,792 KB
testcase_01 AC 91 ms
71,480 KB
testcase_02 AC 91 ms
71,788 KB
testcase_03 AC 93 ms
71,720 KB
testcase_04 AC 91 ms
71,612 KB
testcase_05 AC 92 ms
71,832 KB
testcase_06 AC 93 ms
71,680 KB
testcase_07 AC 93 ms
71,696 KB
testcase_08 AC 2,861 ms
211,624 KB
testcase_09 AC 688 ms
158,464 KB
testcase_10 AC 823 ms
178,828 KB
testcase_11 AC 247 ms
100,700 KB
testcase_12 AC 644 ms
155,348 KB
testcase_13 AC 326 ms
95,348 KB
testcase_14 AC 392 ms
99,012 KB
testcase_15 AC 1,340 ms
175,460 KB
testcase_16 AC 198 ms
96,108 KB
testcase_17 AC 184 ms
83,164 KB
testcase_18 AC 834 ms
137,320 KB
testcase_19 AC 604 ms
112,508 KB
testcase_20 AC 820 ms
123,604 KB
testcase_21 AC 823 ms
127,972 KB
testcase_22 AC 1,489 ms
206,048 KB
testcase_23 AC 1,587 ms
207,964 KB
testcase_24 AC 730 ms
114,308 KB
testcase_25 AC 405 ms
101,256 KB
testcase_26 AC 548 ms
105,796 KB
testcase_27 AC 770 ms
115,644 KB
testcase_28 AC 602 ms
110,124 KB
testcase_29 AC 497 ms
137,888 KB
testcase_30 AC 2,511 ms
202,848 KB
testcase_31 AC 1,307 ms
140,560 KB
testcase_32 AC 849 ms
146,496 KB
testcase_33 AC 860 ms
146,480 KB
testcase_34 AC 814 ms
146,128 KB
testcase_35 AC 801 ms
146,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search_Integer(L,R,cond,default=None):
    """条件式が単調増加であるとき, 整数上で二部探索を行う.
    L: 解の下限
    R: 解の上限
    cond: 条件(1変数関数, 広義単調増加を満たす)
    default: Rで条件を満たさないときの返り値
    """
    if not(cond(R)): return default

    if cond(L): return L

    R+=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C): R=C
        else: L=C
    return R

def check(i):
    k=C[i]

    X=[inf]*(N+1)
    X[1]=0
    Q=deque([1])

    while Q:
        x=Q.popleft()

        f=F[x]
        for y in f:
            if f[y]>k:
                if X[y]>X[x]+1:
                    Q.append(y)
                    X[y]=X[x]+1
            else:
                if X[y]>X[x]:
                    Q.appendleft(y)
                    X[y]=X[x]
    return X[N]<K
#=================================================
import sys
from collections import deque
inf=float("inf")
input=sys.stdin.readline
N,M,K=map(int,input().split())
E=[]
F=[{} for _ in range(N+1)]
C={0}
for _ in range(M):
    u,v,c=map(int,input().split())
    E.append((u,v,c))
    F[u][v]=F[v][u]=c
    C.add(c)

E.append((1,1,0))
F[1][1]=0
C=sorted(C)
print(C[General_Binary_Increase_Search_Integer(0,len(C)-1,check)])
0