結果

問題 No.3490 最高経路問題
コンテスト
ユーザー Dipanshu
提出日時 2026-04-03 22:19:21
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,354 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,484 ms
コンパイル使用メモリ 347,968 KB
実行使用メモリ 12,524 KB
最終ジャッジ日時 2026-04-03 22:19:32
合計ジャッジ時間 3,907 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

#define INF 1e12
int n,m;
vector<vector<pair<int,int>>> g;
vector<int> vis;
vector<int> dis;

bool check(int x)
{
    vis.assign(n+1,0);
    dis.assign(n+1,INF);
    queue<int> qu;
    qu.push(1);
    dis[1]=0;
    while (!qu.empty())
    {
        int curr = qu.front();qu.pop();

        if (vis[curr]) continue;
        vis[curr]=1;

        for (auto [v,h]:g[curr])
        {
            if (h>=x && !vis[v] && dis[v]>dis[curr]+1)
            {
                dis[v]=dis[curr]+1;
                qu.push(v);
            }
        }
    }
    if (dis[n]!=INF) return true;
    return false;
}

void solve()
{
    cin>>n>>m;
    g.assign(n+1,vector<pair<int,int>>());
    for (int i = 0; i < m; i++)
    {
        int u,v,h;cin>>u>>v>>h;
        g[u].push_back({v,h});
        g[v].push_back({u,h});
    }
    int low = 1;
    int high = INF;
    int ans = -1;
    while (low<=high)
    {
        int mid = (low+high)/2;
        if (check(mid))
        {
            ans = mid;
            low = mid+1;
        }
        else
        {
            high = mid-1;
        }
    }

    if (ans==-1) cout << "NaN" << endl;
    else cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    // int t;cin>>t;while(t--)
    solve();
}
0