結果

問題 No.3490 最高経路問題
コンテスト
ユーザー LyricalMaestro
提出日時 2026-04-04 18:49:31
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 1,148 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 120 ms
コンパイル使用メモリ 85,080 KB
実行使用メモリ 111,588 KB
最終ジャッジ日時 2026-04-04 18:49:54
合計ジャッジ時間 5,725 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/3490

from collections import deque

def reachable(N, next_nodes, height):
    queue = deque()
    passed = [False] * N
    passed[0] = True
    queue.append(0)
    while len(queue) > 0:
        v = queue.popleft()
        for w, h in next_nodes[v]:
            if h >= height:
                if not passed[w]:
                    passed[w] = True
                    queue.append(w)
    return passed[N - 1]


def main():
    N, M = map(int, input().split())
    next_nodes = [[] for _ in range(N)]
    max_h = 0
    for _ in range(M):
        u, v, h = map(int, input().split())
        next_nodes[u - 1].append((v - 1, h))
        next_nodes[v - 1].append((u - 1, h))
        max_h = max(max_h, h)


    if not reachable(N, next_nodes, 1):
        print("NaN")
        return
    
    low = 1
    high = max_h
    while high - low > 1:
        mid = (high + low) // 2
        if reachable(N, next_nodes, mid):
            low = mid
        else:
            high = mid
    if reachable(N, next_nodes, high):
        print(high)
    else:
        print(low)
        





if __name__ == "__main__":
    main()
0