結果
| 問題 |
No.1607 Kth Maximum Card
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-20 22:22:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,810 bytes |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 82,500 KB |
| 実行使用メモリ | 301,848 KB |
| 最終ジャッジ日時 | 2024-07-21 12:26:28 |
| 合計ジャッジ時間 | 22,154 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 TLE * 1 -- * 13 |
ソースコード
def oi(): return int(input())
def os(): return input()
def mi(): return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0
input_count = 0
N,M,K = mi()
NODE = N
LOOP_NUM = M
maps = {i:[] for i in range(NODE)}
cost_dict = {}
for i in range(LOOP_NUM):
a,b,c = mi()
maps[a-1].append((b-1, c))
maps[b-1].append((a-1,c))
cost_dict[(a-1,b-1)] = c
cost_dict[(b-1,a-1)] = c
# K 未満の時
from collections import deque
reached = [0] * N ## 1つ前のノードを持たせると微妙に遅くなるのでやめよう
deq = deque([[0,0]])
mins = float("inf")
while deq:
node, count = deq.pop() #BFS
if node == N-1:
if count < K :
mins = 0
break
reached[node] = -1
for next_node, cost in maps[node]:
# 訪問済み判定
if reached[next_node] == -1:
continue
if count+1 <= K:
mins = min(mins, cost)
reached[next_node] = -1
deq.append([next_node, count+1])
# 以下の問題にてテスト済み
# https://atcoder.jp/contests/abc213/tasks/abc213_e
from collections import deque
def zero_one_dfs(target, K):
zero_deq = deque([0])
count=0
use_node = set([])
while True:
one_deq = deque([])
while zero_deq:
node = zero_deq.pop()
# 目的地に到達したら
if node == N-1:
if count < K:
return True
# コスト0の時の移動パターン
for next_node, cost in maps[node]:
if (node,next_node) not in use_node:
use_node.add((node,next_node))
use_node.add((next_node, node))
if cost > target:
one_deq.append(next_node)
else:
zero_deq.append(next_node)
count+=1
zero_deq = one_deq
if count >= K:
return False
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
# 初めてFalseからTrueになるTrueの地点を取得
return zero_one_dfs(arg, K)
def meguru_bisect(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
if mins != 0:
mins = meguru_bisect(0, 10**5 + 1)
print(mins)