結果

問題 No.1607 Kth Maximum Card
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-20 22:28:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,706 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 246,368 KB
最終ジャッジ日時 2023-09-28 17:52:13
合計ジャッジ時間 13,426 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,356 KB
testcase_01 AC 94 ms
71,552 KB
testcase_02 AC 93 ms
71,416 KB
testcase_03 AC 93 ms
71,416 KB
testcase_04 AC 95 ms
71,392 KB
testcase_05 AC 97 ms
71,408 KB
testcase_06 AC 96 ms
71,412 KB
testcase_07 AC 97 ms
71,540 KB
testcase_08 AC 3,270 ms
246,368 KB
testcase_09 AC 2,231 ms
235,748 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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, i))
    maps[b-1].append((a-1,c, i))
# # 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, ind in maps[node]:
                if ind not in use_node:
                    use_node.add(ind)
                    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
mins = meguru_bisect(-1, 2*10**5 + 1)
print(mins)
0