結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2020-07-04 23:39:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 1,412 bytes |
| コンパイル時間 | 1,858 ms |
| コンパイル使用メモリ | 183,388 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:50:35 |
| 合計ジャッジ時間 | 3,068 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
using pp=pair<int,pair<int,int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000
int N,C,V;
vector<int> S,T,Y,M;
int main(){
cin>>N>>C>>V;
S.resize(V);
T.resize(V);
Y.resize(V);
M.resize(V);
Graph G(N);
for(int i=0;i<V;i++){
cin>>S.at(i);
S.at(i)--;
}
for(int i=0;i<V;i++){
cin>>T.at(i);
T.at(i)--;
}
for(int i=0;i<V;i++){
cin>>Y.at(i);
}
for(int i=0;i<V;i++){
cin>>M.at(i);
}
for(int i=0;i<V;i++){
G.at(S.at(i)).push_back(make_pair(T.at(i),i));
}
vector<vector<int>> time(N,vector<int>(301,INF));
time.at(0).at(C)=0;
priority_queue<pp,vector<pp>,greater<pp>> pq;
pq.push(make_pair(time.at(0).at(C),make_pair(0,C)));
while(!pq.empty()){
int v=pq.top().second.first;
int m=pq.top().second.second;
pq.pop();
for(auto e:G.at(v)){
int nv=e.first;
int i=e.second;
if(m-Y.at(i)<0){
continue;
}
if(time.at(nv).at(m-Y.at(i))>time.at(v).at(m)+M.at(i)){
time.at(nv).at(m-Y.at(i))=time.at(v).at(m)+M.at(i);
pq.push(make_pair(time.at(nv).at(m-Y.at(i)),make_pair(nv,m-Y.at(i))));
}
}
}
int ans=INF;
for(int i=0;i<=300;i++){
ans=min(ans,time.at(N-1).at(i));
}
if(ans==INF){
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
}
monnu