結果

問題 No.1607 Kth Maximum Card
ユーザー ああいい
提出日時 2022-03-07 11:24:18
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 887 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 141,620 KB
最終ジャッジ日時 2024-07-22 04:53:18
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
rr = sys.stdin

N,M,K = map(int,rr.readline().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    a,b,c = map(int,rr.readline().split())
    G[a].append((b,c))
    G[b].append((a,c))

import heapq
inf = 10 ** 6
base = 23
mask = (1 << base) - 1
def calc(x):
    dist = [inf] * (N+1)
    dist[1] = 0
    q = [1]
    while q:
        u = heapq.heappop(q)
        d,now = u >> base,u & mask
        if now == N:break
        if dist[now] < d:
            continue
        for v,c in G[now]:
            if c > x:
                c = 1
            else:
                c = 0
            if dist[v] > d + c:
                dist[v] = d + c
                heapq.heappush(q,(d+c) << base | v)
    return dist[N] < K
start = -1
end = 2 * 10 ** 5
while end - start > 1:
    mid = (end + start) // 2
    if calc(mid):
        end = mid
    else:
       start = mid
print(end)
0