結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
ojisan_IT
|
| 提出日時 | 2017-08-11 07:34:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 5,000 ms |
| コード長 | 1,654 bytes |
| コンパイル時間 | 1,892 ms |
| コンパイル使用メモリ | 175,764 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:32:26 |
| 合計ジャッジ時間 | 3,049 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
int dp[51][301] ={}; // dp[N][C] = time
struct edge{
int to,cost,time;
};
vector<edge> G[51];
int s[2222],t[2222],y[2222],m[2222];
int main(){
int n,c,v; cin >> n >> c >> v;
rep(i,v) cin >> s[i];
rep(i,v) cin >> t[i];
rep(i,v) cin >> y[i];
rep(i,v) cin >> m[i];
rep(i,v)
G[s[i]].pb((edge){t[i],y[i],m[i]});
fill_n(dp[0],51*301,INF);
priority_queue<pii,vector<pii>,greater<pii > > q; //cost,position
dp[1][c] = 0;
q.push(mp(c,1));
while(!q.empty()){
int id = q.top().SEC;
int nowc = q.top().FST;
q.pop();
for(int i = 0; i < G[id].size();i++){
if(nowc-G[id][i].cost>=0 && dp[id][nowc]+G[id][i].time < dp[G[id][i].to][nowc-G[id][i].cost]){
dp[G[id][i].to][nowc-G[id][i].cost]=dp[id][nowc]+G[id][i].time;
q.push(mp(nowc-G[id][i].cost,G[id][i].to));
}
}
}
int ans = INF;
for(int i = 0; i < 301; i++)
ans = min(ans,dp[n][i]);
cout << ((ans == INF)? -1 : ans) << endl;
}
ojisan_IT