結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-25 17:45:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,529 bytes |
| コンパイル時間 | 2,648 ms |
| コンパイル使用メモリ | 87,340 KB |
| 実行使用メモリ | 52,224 KB |
| 最終ジャッジ日時 | 2024-06-26 21:08:13 |
| 合計ジャッジ時間 | 7,727 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 4 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int c = sc.nextInt();
int v = sc.nextInt();
int[] starts = new int[v];
for (int i = 0; i < v; i++) {
starts[i] = sc.nextInt() - 1;
}
int[] goals = new int[v];
for (int i = 0; i < v; i++) {
goals[i] = sc.nextInt() - 1;
}
int[] costs = new int[v];
for (int i = 0; i < v; i++) {
costs[i] = sc.nextInt();
}
ArrayList<ArrayList<Path>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
for (int i = 0; i < v; i++) {
int x = sc.nextInt();
graph.get(starts[i]).add(new Path(goals[i], costs[i], x));
graph.get(goals[i]).add(new Path(starts[i], costs[i], x));
}
PriorityQueue<Path> queue = new PriorityQueue<>();
queue.add(new Path(0, c, 0));
int[][] values = new int[n][c + 1];
for (int[] arr : values) {
Arrays.fill(arr, Integer.MAX_VALUE);
}
while (queue.size() > 0) {
Path p = queue.poll();
if (values[p.idx][p.cost] <= p.time) {
continue;
}
for (int i = p.cost; i >= 0 && values[p.idx][i] > p.time; i--) {
values[p.idx][i] = p.time;
}
for (Path x : graph.get(p.idx)) {
if (x.cost <= p.cost) {
queue.add(new Path(x.idx, p.cost - x.cost, p.time + x.time));
}
}
}
if (values[n - 1][0] == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(values[n - 1][0]);
}
}
static class Path implements Comparable<Path> {
int idx;
int cost;
int time;
public Path(int idx, int cost, int time) {
this.idx = idx;
this.cost = cost;
this.time = time;
}
public int compareTo(Path another) {
return time - another.time;
}
}
}
class Utilities {
static String arrayToLineString(Object[] arr) {
return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
}
static String arrayToLineString(int[] arr) {
return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public int[] nextIntArray() throws Exception {
return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten