結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 KazunKazun
提出日時 2021-07-16 23:11:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,739 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 250,232 KB
最終ジャッジ日時 2023-09-20 15:38:31
合計ジャッジ時間 32,737 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,748 KB
testcase_01 AC 91 ms
71,728 KB
testcase_02 AC 92 ms
71,708 KB
testcase_03 WA -
testcase_04 AC 93 ms
71,592 KB
testcase_05 AC 92 ms
71,560 KB
testcase_06 WA -
testcase_07 AC 92 ms
71,640 KB
testcase_08 TLE -
testcase_09 AC 628 ms
145,732 KB
testcase_10 AC 762 ms
164,284 KB
testcase_11 AC 252 ms
98,404 KB
testcase_12 AC 602 ms
143,640 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 193 ms
88,960 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 515 ms
129,608 KB
testcase_30 TLE -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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(cc):
    Q=deque([N])
    X=[inf]*(N+1); X[N]=0
    M=[0]*(N+1)

    while Q:
        x=Q.popleft()

        if M[x]:
            continue

        M[x]=1
        f=F[x]

        for y in f:
            c=f[y]
            if c>cc:
                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]

    for u,v,c in E:
        if c<=cc and (X[u]<K or X[v]<K):
            return True
    return False
#=================================================
def is_zero():
    Q=deque([1])
    X=[-1]*(N+1); X[1]=0
    while Q:
        x=Q.popleft()
        for y in F[x]:
            if X[y]==-1:
                X[y]=X[x]+1
                Q.append(y)
    return X[N]<K
#=================================================
import sys
from collections import deque
inf=float("inf")
N,M,K=map(int,input().split())
E=[]
F=[{} for _ in range(N+1)]
c_max=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_max=max(c_max,c)

E.append((1,1,0))
F[1][1]=0

if is_zero():
    exit(print(0))

print(General_Binary_Increase_Search_Integer(1,c_max,check,None))
0