結果

問題 No.1607 Kth Maximum Card
ユーザー horitaka1999horitaka1999
提出日時 2021-12-11 00:22:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,095 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 281,160 KB
最終ジャッジ日時 2023-09-26 01:34:23
合計ジャッジ時間 7,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,388 KB
testcase_01 AC 73 ms
71,152 KB
testcase_02 AC 75 ms
71,464 KB
testcase_03 AC 79 ms
71,156 KB
testcase_04 AC 75 ms
71,148 KB
testcase_05 AC 76 ms
71,508 KB
testcase_06 AC 76 ms
71,156 KB
testcase_07 AC 72 ms
71,416 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
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 #

N,M,K = map(int,input().split())
board = []
for _ in range(M):
    u,v,c = map(int,input().split())
    u-=1
    v-=1
    board.append((u,v,c))
from heapq import heappush,heappop
#edge[a].append((b,cost))
def dijekstra(st,dis,edge):
    q = []
    dis[st] = 0
    q.append((0,st))
    while q:
        t,now = heappop(q)
        if t > dis[now]:
            continue
        for next,cost in edge[now]:
            if dis[next] > cost + dis[now]:
                dis[next] = cost + dis[now]
                heappush(q,(dis[next],next))
def is_ok(x):
    edge = [[] for _ in range(N)]
    for i in range(M):
        u,v,c = board[i]
        if c > x:
            edge[u].append((v,1))
            edge[v].append((u,1))
        else:
            edge[u].append((v,0))
            edge[v].append((u,0))
    INF = float('inf')
    dis = [INF for _ in range(N)]
    dijekstra(0,dis,edge)
    if dis[N-1] <= K -1:
        return True
    else:
        return False

ok = 2 * 10 ** 5
ng = -1
while ok - ng > 1:
    x = (ng+ok)//2
    if is_ok(x):
        ok = x
    else:
        ng = x
print(ok)
    
0