結果

問題 No.1607 Kth Maximum Card
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-20 22:22:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,810 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 306,252 KB
最終ジャッジ日時 2023-09-28 17:47:23
合計ジャッジ時間 25,588 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,548 KB
testcase_01 AC 96 ms
71,800 KB
testcase_02 AC 94 ms
71,840 KB
testcase_03 AC 94 ms
71,772 KB
testcase_04 AC 94 ms
71,720 KB
testcase_05 AC 93 ms
71,776 KB
testcase_06 AC 93 ms
71,664 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 739 ms
172,604 KB
testcase_10 AC 860 ms
204,344 KB
testcase_11 AC 268 ms
102,480 KB
testcase_12 AC 668 ms
170,720 KB
testcase_13 WA -
testcase_14 AC 1,074 ms
199,336 KB
testcase_15 WA -
testcase_16 AC 333 ms
98,036 KB
testcase_17 AC 339 ms
100,916 KB
testcase_18 AC 3,219 ms
294,860 KB
testcase_19 AC 2,019 ms
275,100 KB
testcase_20 WA -
testcase_21 AC 2,477 ms
289,508 KB
testcase_22 TLE -
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))
    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)
0