結果
| 問題 |
No.1607 Kth Maximum Card
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-11 00:29:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,190 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 376,396 KB |
| 最終ジャッジ日時 | 2024-07-18 21:15:29 |
| 合計ジャッジ時間 | 41,705 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 TLE * 3 -- * 5 |
ソースコード
N,M,K = map(int,input().split())
board = []
for _ in range(M):
u,v,c = map(int,input().split())
u-=1
v-=1
board.append((u,v,c))
from collections import deque
#edge[a].append((b,cost))
def bfs(st,dis,edge):
q = deque()
dis[st] = 0
q.append((0,st))
while q:
t,now = q.popleft()
if t > dis[now]:
continue
for next,cost in edge[now]:
if dis[next] > cost + dis[now]:
dis[next] = cost + dis[now]
if cost == 0:
q.appendleft((dis[next],next))
else:
q.append((dis[next],next))
def is_ok(x):
edge = [[] for _ in range(N)]
for i in range(M):
u,v,c = board[i]
if c > x:
edge[u].append((v,1))
edge[v].append((u,1))
else:
edge[u].append((v,0))
edge[v].append((u,0))
INF = float('inf')
dis = [INF for _ in range(N)]
bfs(0,dis,edge)
if dis[N-1] <= K -1:
return True
else:
return False
ok = 2 * 10 ** 5
ng = -1
while ok - ng > 1:
x = (ng+ok)//2
if is_ok(x):
ok = x
else:
ng = x
print(ok)