結果

問題 No.1 道のショートカット
ユーザー _shim0123__shim0123_
提出日時 2015-05-05 12:08:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,471 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 76,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 12:09:23
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

#define INF 10000000
typedef pair < unsigned, unsigned > P;

class edge{
public:
	unsigned to;
	unsigned cost;
	unsigned time;
	edge(unsigned a, unsigned b, unsigned c) {
		to = a;
		cost = b;
		time = c;
	}
};

int main(void) {
	unsigned N = 0, C = 0, V = 0;
	unsigned S[1500] = {0}, T[1500] = {0}, Y[1500] = {0}, M[1500] = {0};
	vector<edge> G[51];
	priority_queue<P ,vector<P>, greater<P>> que;
	unsigned time[51], money[51] = {0};

	cin >> N >> C >> V;

	for(unsigned i = 0; i < V; i++){
		cin >> S[i];
	}
	for(unsigned i = 0; i < V; i++){
		cin >> T[i];
	}
	for(unsigned i = 0; i < V; i++){
		cin >> Y[i];
	}
	for(unsigned i = 0; i < V; i++){
		cin >> M[i];
	}

	for(unsigned i = 0; i < V; i++){
		edge e(T[i], Y[i], M[i]);
		G[S[i]].push_back(e);
	}

	for(unsigned i = 1; i <= N; i++){
		time[i] = INF;
	}

	que.push(P(1,0));
	time[1] = 0;
	money[1] = 0;

	while(!que.empty()){
		P p = que.top();
		que.pop();
		unsigned pos = p.first, t = p.second;

		if(time[pos] < t){
			continue;
		}

		for(unsigned i = 1; i <= N; i++){
			for(auto e : G[pos]){
				if(time[e.to] > time[pos] + e.time && C>=money[pos]+e.cost){
					money[e.to] = money[pos] + e.cost;
					time[e.to] = time[pos] + e.time;
					que.push(P(e.to,time[e.to]));
				}
			}
		}
	}

	if(time[N] != INF){
		cout << time[N] << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}
0