結果

問題 No.2387 Yokan Factory
ユーザー 憩いの場
提出日時 2023-07-21 22:38:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 383 ms / 5,000 ms
コード長 1,962 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 83,628 KB
実行使用メモリ 9,584 KB
最終ジャッジ日時 2024-09-22 00:07:43
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
class Node
{
public :
int id;
int cost;
int width;
Node() = default;
Node( int id, int cost, int width ) : id( id ), cost( cost ), width( width ) {};
bool operator < ( const Node &node ) const
{
return this->cost < node.cost;
}
};
int main( void )
{
int N, M;
long long X;
cin >> N >> M >> X;
vector<vector<Node>> Graph( N + 1 );
int u, v, a, b;
int max_width = 0;
for( int i = 0; i < M; i++ )
{
cin >> u >> v >> a >> b;
max_width = max( max_width, b );
Graph[u].push_back( Node( v, a, b ) );
Graph[v].push_back( Node( u, a, b ) );
}
int left = 0, right = max_width + 1;
int mid;
vector<long long> shortest( N + 1 );
while( left < right )
{
mid = ( left + right ) / 2 + 1;
shortest.assign( N + 1, -1 );
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
shortest[1] = 0;
q.push( make_pair( 0, 1 ) );
pair<long long, int> cur;
while( !q.empty() )
{
cur = q.top(), q.pop();
if( cur.first > shortest[cur.second] ) continue;
for( Node next : Graph[cur.second] )
{
if( next.width >= mid && ( shortest[next.id] == -1 || shortest[next.id] > shortest[cur.second] + next.cost ) )
{
shortest[next.id] = shortest[cur.second] + next.cost;
q.push( make_pair( shortest[next.id], next.id ) );
}
}
}
if( shortest[N] == -1 || shortest[N] > X )
{
right = mid - 1;
}
else
{
left = mid;
}
}
if( left == 0 )
{
cout << -1 << endl;
}
else
{
cout << left << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0