結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-04 23:02:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,146 bytes |
| コンパイル時間 | 4,210 ms |
| コンパイル使用メモリ | 79,092 KB |
| 実行使用メモリ | 66,668 KB |
| 最終ジャッジ日時 | 2024-07-08 04:23:08 |
| 合計ジャッジ時間 | 12,938 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 1 -- * 32 |
ソースコード
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;
public class Main_yukicoder1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int c = sc.nextInt();
int v = sc.nextInt();
int[] s = new int[v];
int[] t = new int[v];
int[] y = new int[v];
int[] m = new int[v];
for (int i = 0; i < v; i++) {
s[i] = sc.nextInt();
}
for (int i = 0; i < v; i++) {
t[i] = sc.nextInt();
}
for (int i = 0; i < v; i++) {
y[i] = sc.nextInt();
}
for (int i = 0; i < v; i++) {
m[i] = sc.nextInt();
}
List<List<Triple>> edges = new ArrayList<List<Triple>>();
for (int i = 0; i < n; i++) {
edges.add(new ArrayList<Triple>());
}
for (int i = 0; i < v; i++) {
edges.get(s[i] - 1).add(new Triple(t[i] - 1, y[i], m[i]));
}
Deque<Integer> st = new ArrayDeque<Integer>();
Deque<Integer> cst = new ArrayDeque<Integer>();
Deque<Integer> mst = new ArrayDeque<Integer>();
st.push(0);
cst.push(0);
mst.push(0);
int min = Integer.MAX_VALUE;
while (!st.isEmpty()) {
int e = st.pop();
int ce = cst.pop();
int me = mst.pop();
if (e == n - 1) {
min = Math.min(min, me);
continue;
}
for (Triple next : edges.get(e)) {
int ne = next.a;
int nce = ce + next.b;
int nme = me + next.c;
if (nce <= c) {
st.push(ne);
cst.push(nce);
mst.push(nme);
}
}
}
if (min == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(min);
}
sc.close();
}
private static class Triple {
int a;
int b;
int c;
Triple(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
}
}