結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2018-02-28 16:22:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,943 bytes |
コンパイル時間 | 709 ms |
コンパイル使用メモリ | 76,052 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:34:46 |
合計ジャッジ時間 | 1,843 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <iostream> #include <queue> #include <map> using namespace std; struct Info{ int from,to,cost,time; }; struct Dik{ int vertex; int cost,time; // bool operator<(const Dik &other)const{ // return cost>other.cost; // } }; int main(){ int N,current,ver; cin >> N >> current; cin >> ver; Info info[2500]; map<int,int> dp; for(int i=0 ; i<ver ; i++ ){ cin >> info[i].from; dp[info[i].from]=1000000000; } for(int i=0 ; i<ver ; i++ ){ cin >> info[i].to; dp[info[i].to]=1000000000; } for(int i=0 ; i<ver ; i++ ) cin >> info[i].cost; for(int i=0 ; i<ver ; i++ ) cin >> info[i].time; queue<Dik> circle; Dik now;now.vertex=1; now.cost=now.time=0; circle.push(now); int min=1000000000; while(circle.size()!=0){ now=circle.front();circle.pop(); if(now.cost>current)continue; if(now.vertex==N) if(min>now.time)min=now.time; Dik next; if(min<now.time)continue; // if(dp[now.vertex]<now.time){ // cout << now.time<< endl; // continue; // } dp[now.vertex]=now.time; for(int i=0 ; i<ver ; i++ ){ if(info[i].from==now.vertex){ next.vertex=info[i].to; next.cost=now.cost+info[i].cost; next.time=now.time+info[i].time; circle.push(next); } } } if(min==1000000000) cout<<-1<<endl; else cout << min << endl; return 0; }