結果

問題 No.1607 Kth Maximum Card
ユーザー mkawa2mkawa2
提出日時 2023-02-24 13:59:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,752 ms / 3,500 ms
コード長 1,568 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 86,240 KB
実行使用メモリ 151,380 KB
最終ジャッジ日時 2023-10-09 23:16:23
合計ジャッジ時間 24,263 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,212 KB
testcase_01 AC 80 ms
70,976 KB
testcase_02 AC 83 ms
71,080 KB
testcase_03 AC 79 ms
71,096 KB
testcase_04 AC 83 ms
71,092 KB
testcase_05 AC 82 ms
71,268 KB
testcase_06 AC 81 ms
71,220 KB
testcase_07 AC 82 ms
70,932 KB
testcase_08 AC 1,037 ms
124,800 KB
testcase_09 AC 678 ms
115,596 KB
testcase_10 AC 1,752 ms
151,380 KB
testcase_11 AC 202 ms
90,608 KB
testcase_12 AC 982 ms
118,792 KB
testcase_13 AC 221 ms
84,216 KB
testcase_14 AC 240 ms
86,776 KB
testcase_15 AC 850 ms
119,176 KB
testcase_16 AC 232 ms
84,708 KB
testcase_17 AC 145 ms
79,548 KB
testcase_18 AC 585 ms
101,024 KB
testcase_19 AC 394 ms
92,456 KB
testcase_20 AC 515 ms
96,400 KB
testcase_21 AC 493 ms
98,356 KB
testcase_22 AC 864 ms
131,516 KB
testcase_23 AC 884 ms
131,104 KB
testcase_24 AC 430 ms
91,656 KB
testcase_25 AC 268 ms
87,072 KB
testcase_26 AC 367 ms
88,308 KB
testcase_27 AC 484 ms
92,576 KB
testcase_28 AC 408 ms
90,064 KB
testcase_29 AC 926 ms
107,248 KB
testcase_30 AC 1,465 ms
128,984 KB
testcase_31 AC 928 ms
106,412 KB
testcase_32 AC 265 ms
106,128 KB
testcase_33 AC 261 ms
106,128 KB
testcase_34 AC 299 ms
106,536 KB
testcase_35 AC 345 ms
106,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from collections import deque

n, m, k = LI()
to = [[] for _ in range(n)]
for _ in range(m):
    u, v, c = LI1()
    c += 1
    to[u].append((v, c))
    to[v].append((u, c))

def binary_search(l, r, minimize):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(m):
    q = deque([0])
    dist = [inf]*n
    dist[0] = 0
    while q:
        u = q.popleft()
        if dist[u] >= k: return False
        for v, c in to[u]:
            nd = dist[u]+(c > m)
            if nd >= dist[v]: continue
            dist[v] = nd
            if c > m:
                q.append(v)
            else:
                q.appendleft(v)
        if dist[-1] < k: return True
    return False

print(binary_search(0, 200000, True))
0