結果

問題 No.1 道のショートカット
ユーザー stack9996stack9996
提出日時 2015-08-27 12:01:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 79,736 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:27:16
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <cmath>
#include <queue>

#define rep(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
struct edge{ int to, time, cost; };

const int max = 51;
const int inf = (int)1e+9;

int n, c;
P cost[max];
std::vector<edge> node[max];

void dijkstra(int s){
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;
	rep(i, n)cost[i].first = inf, cost[i].second = inf;
	cost[s].first = 0, cost[s].second = 0;
	que.push(P(0, s));
	while (!que.empty()){
		P p = que.top();
		que.pop();
		if (cost[p.second].first < p.second)continue;
		rep(i, node[p.second].size()){
			edge e = node[p.second][i];
			if (p.first + e.time < cost[e.to].first && cost[p.second].second + e.cost <= c){
				cost[e.to].first = p.first + e.time;
				cost[e.to].second = cost[p.second].second + e.cost;
				que.push(P(cost[e.to].first, e.to));
			}
		}
	}
}

int main(){
	int v;
	int s[51], t[51], y[51], m[51];
	std::cin >> n >> c >> v;
	rep(i, n)std::cin >> s[i];
	rep(i, n)std::cin >> t[i];
	rep(i, n)std::cin >> y[i];
	rep(i, n)std::cin >> m[i];
	rep(i, n){
		edge a;
		a.to = t[i] - 1;
		a.cost = y[i];
		a.time = m[i];
		node[s[i] - 1].push_back(a);
	}
	dijkstra(0);
	std::cout << (cost[n - 1].first == inf ? -1 : cost[n - 1].first) << std::endl;
	return 0;
}
0