結果
問題 |
No.1607 Kth Maximum Card
|
ユーザー |
👑 ![]() |
提出日時 | 2021-07-16 23:11:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,739 bytes |
コンパイル時間 | 834 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 246,296 KB |
最終ジャッジ日時 | 2024-07-06 10:42:58 |
合計ジャッジ時間 | 20,487 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 24 |
ソースコード
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))