結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 KazunKazun
提出日時 2021-07-17 00:00:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,567 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 71,928 KB
最終ジャッジ日時 2023-09-20 16:30:58
合計ジャッジ時間 6,777 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,928 KB
testcase_01 AC 92 ms
71,836 KB
testcase_02 AC 92 ms
71,856 KB
testcase_03 AC 93 ms
71,568 KB
testcase_04 AC 94 ms
71,432 KB
testcase_05 AC 92 ms
71,408 KB
testcase_06 AC 90 ms
71,724 KB
testcase_07 AC 92 ms
71,692 KB
testcase_08 TLE -
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 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 zero_one_bfs(start,k):
    Q=deque([start])
    X=[inf]*(N+1); X[start]=0

    M=[0]*(N+1)

    while Q:
        x=Q.popleft()
        if M[x]: continue

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

        for y in f:
            if f[y]>k:
                if X[y]>X[x]+1:
                    X[y]=X[x]+1
                    Q.append(y)
            else:
                if X[y]>X[x]:
                    X[y]=X[x]
                    Q.appendleft(y)
    return X

def check(k):
    X=zero_one_bfs(1,k)
    Y=zero_one_bfs(N,k)

    for u,v,c in E:
        if c>k:
            continue

        if (X[u]+Y[v]<K or Y[u]+X[v]<K):
            return True

    return False
#=================================================
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_max=0
for _ in range(M):
    u,v,c=map(int,input().split())

    c_max=max(c_max,c)
    E.append((u,v,c))

    F[u][v]=F[v][u]=c

E.append((1,1,0))
F[1][1]=0
print(General_Binary_Increase_Search_Integer(0,c_max+1,check))
0