結果

問題 No.1 道のショートカット
ユーザー ゴリポン先生ゴリポン先生
提出日時 2023-09-08 09:31:03
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,196 bytes
コンパイル時間 5,418 ms
コンパイル使用メモリ 235,880 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 09:31:11
合計ジャッジ時間 8,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

module main;

import std;
// https://algo-logic.info/dijkstra/ より
struct Edge {
	int to, cost, time;
}
int N, C, V;
int[] S, T, Y, M;
Edge[][] G;
int[] t;
immutable INF = int.max / 2;
// ダイクストラ法
alias P = Tuple!(int, int, int);	// 仮の最短時間、頂点、かかったコストの組
void dijkstra(int s)
{
	t[] = INF;
	t[s] = 0;
	auto que = new RedBlackTree!(P, (a, b) => a[0] < b[0] || (a[0] == b[0] && a[1] < b[1]))(P(0, s, 0));
	while (!que.empty) {
		P p = que.front;
		que.removeFront;
		int v = p[1];
		// 最短時間でなければ無視
		if (t[v] < p[0]) continue;
		foreach (e; G[v]) {
			if (t[e.to] <= t[v] + e.time || p[2] + e.cost > C) continue;
			t[e.to] = t[v] + e.time;
			que.insert(P(t[e.to], e.to, p[2] + e.cost));
		}
	}
}
void main()
{
	// 入力
	N = readln.chomp.to!int;
	C = readln.chomp.to!int;
	V = readln.chomp.to!int;
	S = readln.split.to!(int[]);
	T = readln.split.to!(int[]);
	Y = readln.split.to!(int[]);
	M = readln.split.to!(int[]);
	t = new int[](N + 1);
	G = new Edge[][](N + 1);
	foreach (i; 0 .. V) {
		G[S[i]] ~= Edge(T[i], Y[i], M[i]);
	}
	// 答えの計算
	dijkstra(1);
	// 答えの出力
	writeln(t[N] == INF ? -1 : t[N]);
}
0