結果

問題 No.1 道のショートカット
ユーザー TAISA_TAISA_
提出日時 2018-05-30 22:53:47
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,257 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 154,508 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:19:27
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
4,376 KB
testcase_16 RE -
testcase_17 AC 1 ms
4,376 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 2 ms
4,380 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 2 ms
4,380 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[51],v[51],y[51],t[51];
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