結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2015-02-10 09:56:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,315 bytes |
コンパイル時間 | 1,791 ms |
コンパイル使用メモリ | 174,024 KB |
実行使用メモリ | 208,292 KB |
最終ジャッジ日時 | 2024-07-08 03:46:03 |
合計ジャッジ時間 | 8,362 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 TLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef pair<int,int> P; typedef pair<int,pair<int,int>> PP; typedef long long LL; const double EPS = 1e-8; const int INF = 1e9; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; struct edge{ int to,cost,tm; }; int used[51]; int bfs(vector<vector<edge>>& es,int C,int G){ //時間、コスト、どこにいるか priority_queue<PP,vector<PP>,greater<PP>> pq; pq.push(make_pair(0,make_pair(C,0))); used[0] = 1; int ret = INF; while(!pq.empty()){ PP pp = pq.top();pq.pop(); if(pp.second.second == G){ ret = min(ret,pp.first);continue;} for(int i=0;i<es[pp.second.second].size();i++){ int v = es[pp.second.second][i].to; int c = pp.second.first - es[pp.second.second][i].cost; int tm = pp.first + es[pp.second.second][i].tm; if( c < 0)continue; pq.push(make_pair(tm,make_pair(c,v))); used[v] = 1; } } return ret==INF ? -1 : ret; } int main(void) { int N,C,V; vector<vector<edge>>es; cin >> N >> C >> V; es.resize(N); vector<int> S(V),T(V),Y(V),M(V); for(int i=0;i<V;i++)cin >> S[i]; for(int i=0;i<V;i++)cin >> T[i]; for(int i=0;i<V;i++)cin >> Y[i]; for(int i=0;i<V;i++)cin >> M[i]; for(int i=0;i<V;i++)es[S[i]-1].push_back(edge{T[i]-1,Y[i],M[i]}); cout << bfs(es,C,N-1) << endl; return 0; }