結果

問題 No.3490 最高経路問題
コンテスト
ユーザー Facade
提出日時 2026-04-03 21:56:49
言語 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  
実行時間 102 ms / 2,000 ms
コード長 747 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,939 ms
コンパイル使用メモリ 341,948 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2026-04-03 21:56:58
合計ジャッジ時間 4,776 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
using namespace std;
int inf=1e18;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n,m;cin>>n>>m;
	vector<vector<pair<int,int>>>g(n);
	for(int i=0;i<m;i++){
		int u,v,h;cin>>u>>v>>h;
		u--;v--;
		g[u].push_back({v,h});
		g[v].push_back({u,h});
	}
	int ng=1e10,ok=0;
	while(ng-ok>1){
		int c=(ok+ng)/2;
		vector<bool>vis(n);
		vis[0]=true;
		deque<int>que;
		que.push_back(0);
		while(!que.empty()){
			int now=que.front();
			que.pop_front();
			for(auto to:g[now]){
				if(c<=to.second&&!vis[to.first]){
					vis[to.first]=true;
					que.push_back(to.first);
				}
			}
		}
		if(vis[n-1])ok=c;
		else ng=c;
	}
	if(ok==0){
		cout<<"NaN"<<endl;
	}else{
		cout<<ok<<endl;
	}
}
0