結果

問題 No.1 道のショートカット
ユーザー pocaristpocarist
提出日時 2015-07-14 13:08:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,018 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 89,980 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:23:51
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <complex>
#include <cassert>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <limits>

using namespace std;

const int INF = numeric_limits<int>::max()/4;

//http://www.prefield.com/algorithm/graph/dijkstra.html
typedef int Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Weight weight2;
	Edge(int src, int dst, Weight weight, Weight weight2) :
		src(src), dst(dst), weight(weight), weight2(weight2) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return make_pair(e.weight, e.weight2) > make_pair(f.weight, f.weight2); // !!INVERSE!!
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void shortestPath(const Graph &g, int s,
	vector<Weight> &dist, vector<int> &prev, int C) {
	int n = g.size();
	dist.assign(n, INF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
	for (Q.push(Edge(-2, s, 0, 0)); !Q.empty();) {
		Edge e = Q.top(); Q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		for (const auto& f : g[e.dst]) {
			if (dist[f.dst] > e.weight + f.weight && C >= e.weight2 + f.weight2) {
				dist[f.dst] = e.weight + f.weight;
				Q.push(Edge(f.src, f.dst, e.weight + f.weight, e.weight2 + f.weight2));
			}
		}
	}
}

int main()
{
	Graph G;
	int N, C, V;
	{
		cin >> N >> C >> V;
		vector<int> S(V), T(V), Y(V), M(V);
		for (int i = 0; i < V; i++) {
			cin >> S[i];
			S[i]--;
		}
		for (int i = 0; i < V; i++) {
			cin >> T[i];
			T[i]--;
		}
		for (int i = 0; i < V; i++) {
			cin >> Y[i];
		}
		for (int i = 0; i < V; i++) {
			cin >> M[i];
		}
		G.assign(N, vector<Edge>());
		for (int i = 0; i < V; i++) {
			G[S[i]].push_back(Edge(S[i], T[i], M[i], Y[i]));
		}
	}
	vector<Weight> dist;
	vector<Weight> prev;
	shortestPath(G, 0, dist, prev, C);
	int ans = dist[N - 1];
	cout << (ans == INF ? -1 : ans) << endl;
	return 0;
}
0