結果

問題 No.1607 Kth Maximum Card
ユーザー shotoyooshotoyoo
提出日時 2021-07-16 22:30:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,360 ms / 3,500 ms
コード長 1,184 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 146,040 KB
最終ジャッジ日時 2023-09-20 14:47:19
合計ジャッジ時間 27,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,612 KB
testcase_01 AC 97 ms
71,536 KB
testcase_02 AC 100 ms
71,400 KB
testcase_03 AC 96 ms
71,496 KB
testcase_04 AC 97 ms
71,464 KB
testcase_05 AC 95 ms
71,608 KB
testcase_06 AC 95 ms
71,328 KB
testcase_07 AC 94 ms
71,516 KB
testcase_08 AC 1,746 ms
138,120 KB
testcase_09 AC 984 ms
120,196 KB
testcase_10 AC 2,175 ms
146,040 KB
testcase_11 AC 292 ms
89,288 KB
testcase_12 AC 1,460 ms
123,340 KB
testcase_13 AC 323 ms
87,740 KB
testcase_14 AC 353 ms
87,704 KB
testcase_15 AC 1,217 ms
119,100 KB
testcase_16 AC 291 ms
85,396 KB
testcase_17 AC 209 ms
80,232 KB
testcase_18 AC 770 ms
105,552 KB
testcase_19 AC 503 ms
93,352 KB
testcase_20 AC 638 ms
96,908 KB
testcase_21 AC 746 ms
99,876 KB
testcase_22 AC 1,173 ms
131,644 KB
testcase_23 AC 1,299 ms
133,364 KB
testcase_24 AC 739 ms
96,400 KB
testcase_25 AC 482 ms
87,816 KB
testcase_26 AC 562 ms
88,824 KB
testcase_27 AC 754 ms
96,684 KB
testcase_28 AC 645 ms
91,332 KB
testcase_29 AC 1,323 ms
110,944 KB
testcase_30 AC 2,360 ms
135,524 KB
testcase_31 AC 1,254 ms
105,920 KB
testcase_32 AC 306 ms
99,916 KB
testcase_33 AC 296 ms
100,332 KB
testcase_34 AC 340 ms
100,208 KB
testcase_35 AC 313 ms
100,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


# グラフの読み込み・重みあり
n,m,k = map(int, input().split())
ns = [[] for _ in range(n)]
mc = 0
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append((c,v))
    ns[v].append((c,u))
    mc = max(mc, c)
from collections import deque
def bfs01(start, ns, x):
    n = len(ns)
    dist = [-1]*n
    dist[start] = 0
    q = deque([start])
    while q:
        u = q.popleft()
        if u==n-1:
            break
        d = dist[u]
        for c,v in ns[u]:
            c = int(c>x)
            if c==1:
                if dist[v]==-1:
                    dist[v] = d + 1
                    q.append(v)
            else:
                if dist[v]==-1 or d<dist[v]:
                    dist[v] = d
                    q.appendleft(v)
    return dist[n-1]<=k-1
ng = -1
ok = mc+1
while abs(ok-ng)>1:
    mm = (ok+ng)//2
    if bfs01(0, ns, mm):
        ok = mm
    else:
        ng = mm
ans = ok
print(ans)
0