結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2016-11-21 20:49:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 1,626 ms |
コンパイル使用メモリ | 181,336 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:27:49 |
合計ジャッジ時間 | 2,659 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; signed main(){ int N, C, V; cin >> N >> C >> V; vector< int > S( V ), T( V ), Y( V ), M( V ); for( int i = 0; i < V; ++i ) cin >> S[ i ], --S[ i ]; for( int i = 0; i < V; ++i ) cin >> T[ i ], --T[ i ]; for( int i = 0; i < V; ++i ) cin >> Y[ i ]; for( int i = 0; i < V; ++i ) cin >> M[ i ]; priority_queue< tuple< int, int, int >, vector< tuple< int, int, int > >, greater< tuple< int, int, int > > > pq; vector< vector< int > > dp( N, vector< int >( C + 1, INF ) ); pq.emplace( dp[ 0 ][ C ] = 0, 0, C ); while( not pq.empty() ){ int d, u, c; tie( d, u, c ) = pq.top(); pq.pop(); if( u == N - 1 ) cout << d << endl, exit( 0 ); if( d != dp[ u ][ c ] ) continue; for( int i = 0; i < V; ++i ) if( u == S[ i ] and c >= Y[ i ] ) if( dp[ T[ i ] ][ c - Y[ i ] ] > dp[ u ][ c ] + M[ i ] ) dp[ T[ i ] ][ c - Y[ i ] ] = dp[ u ][ c ] + M[ i ], pq.emplace( dp[ T[ i ] ][ c - Y[ i ] ], T[ i ], c - Y[ i ] ); } cout << -1 << endl; return 0; }