結果

問題 No.1 道のショートカット
ユーザー TAISA_TAISA_
提出日時 2018-05-30 22:55:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,265 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 154,336 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:14:31
合計ジャッジ時間 3,024 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,384 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
struct edge{int to,cost,time;};
vector<edge> G[51];
int u[1510],v[1510],y[1510],t[1510];
int d[310][51];
int main(){
	int n,c,m;cin>>n>>c>>m;
	for(int i=0;i<m;i++)cin>>u[i];
	for(int i=0;i<m;i++)cin>>v[i];
	for(int i=0;i<m;i++)cin>>y[i];
	for(int i=0;i<m;i++)cin>>t[i];
	for(int i=0;i<m;i++){
		u[i]--;v[i]--;
		G[u[i]].push_back({v[i],y[i],t[i]});
	}
	priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>> > q;;
	for(int i=0;i<=c;i++)for(int j=0;j<n;j++)d[i][j]=INF;
	q.push(make_pair(0,P(0,0)));
	d[0][0]=0;
	while(!q.empty()){
		pair<int,P> p=q.top();
		q.pop();
		int vv=p.second.second;int cc=p.second.first;int tt=p.first;
		for(auto e:G[vv]){
			if(cc+e.cost>c)continue;
			if(d[cc+e.cost][e.to]<=d[cc][vv]+e.time)continue;
			d[cc+e.cost][e.to]=d[cc][vv]+e.time;
			q.push(make_pair(d[cc+e.cost][e.to],P(cc+e.cost,e.to)));
		}
	}
	int ans=INF;
	for(int i=0;i<=c;i++){
		ans=min(d[i][n-1],ans);
	}
	if(ans==INF){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
    return 0;
}
0