結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-08 09:31:03 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,196 bytes |
| コンパイル時間 | 6,146 ms |
| コンパイル使用メモリ | 243,176 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-26 02:34:31 |
| 合計ジャッジ時間 | 7,546 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 WA * 8 |
ソースコード
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]);
}