結果
問題 | No.1607 Kth Maximum Card |
ユーザー |
|
提出日時 | 2024-09-03 02:28:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,232 ms / 3,500 ms |
コード長 | 1,357 bytes |
コンパイル時間 | 412 ms |
コンパイル使用メモリ | 82,604 KB |
実行使用メモリ | 172,624 KB |
最終ジャッジ日時 | 2024-09-03 02:28:58 |
合計ジャッジ時間 | 26,870 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
## https://yukicoder.me/problems/no/1607from collections import dequeMAX_INT = 10 ** 18def solve(N, next_nodes, K, value):# 01BFSで問題を解くdists = [MAX_INT ] * Ndists[0] = 0queue = deque()queue.append(0)while len(queue) > 0:v = queue.popleft()for w, cost in next_nodes[v]:if cost > value:if dists[w] > dists[v] + 1:dists[w] = dists[v] + 1queue.append(w)else:if dists[w] > dists[v]:dists[w] = dists[v]queue.appendleft(w)return dists[N - 1] < Kdef main():N, M, K = map(int, input().split())edges = []max_c = 0for _ in range(M):u, v, c = map(int, input().split())edges.append((u - 1, v - 1, c))max_c = max(c, max_c)next_nodes = [[] for _ in range(N)]for u, v, c in edges:next_nodes[u].append((v, c))next_nodes[v].append((u, c))low = 0high = max_cwhile high - low > 1:mid = (high + low) // 2if solve(N, next_nodes, K, mid):high = midelse:low = midif solve(N, next_nodes, K, low):print(low)else:print(high)if __name__ == "__main__":main()