結果

問題 No.1607 Kth Maximum Card
ユーザー rlangevin
提出日時 2023-10-04 08:58:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,017 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 401,992 KB
最終ジャッジ日時 2024-07-26 14:19:53
合計ジャッジ時間 7,779 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
Edge = []
for i in range(M):
    u, v, c = map(int, input().split())
    u, v = u - 1, v - 1
    Edge.append((u, v, c))

from collections import *
def check(m):
    G = [[] for i in range(N)]
    for u, v, c in Edge:
        if c > m:
            G[u].append((v, 1))
            G[v].append((u, 1))
        else:
            G[u].append((v, 0))
            G[v].append((u, 0))

    Q = deque()
    inf = 10 ** 18
    dist = [inf] * N
    dist[0] = 0
    Q.append(0)
    while Q:
        u = Q.popleft()
        for v, c in G[u]:
            if dist[v] <= dist[u] + c:
                continue
            dist[v] = dist[u] + c
            if c == 0:
                Q.appendleft(v)
            else:
                Q.append(v)

    return dist[-1] < K


if check(0):
    print(0)
    exit()

yes = 2 * 10 ** 5 + 5
no = 0
while yes - no != 1:
    mid = (yes + no)//2
    if check(mid):
        yes = mid
    else:
        no = mid

print(yes)
0