結果
問題 | No.2805 Go to School |
ユーザー | tenten |
提出日時 | 2024-07-17 10:22:49 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,308 ms / 2,000 ms |
コード長 | 3,084 bytes |
コンパイル時間 | 2,594 ms |
コンパイル使用メモリ | 80,168 KB |
実行使用メモリ | 112,512 KB |
最終ジャッジ日時 | 2024-07-17 10:23:26 |
合計ジャッジ時間 | 33,681 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,140 KB |
testcase_01 | AC | 53 ms
50,132 KB |
testcase_02 | AC | 54 ms
50,456 KB |
testcase_03 | AC | 57 ms
49,992 KB |
testcase_04 | AC | 797 ms
93,564 KB |
testcase_05 | AC | 1,161 ms
94,856 KB |
testcase_06 | AC | 694 ms
76,160 KB |
testcase_07 | AC | 826 ms
79,072 KB |
testcase_08 | AC | 1,290 ms
103,992 KB |
testcase_09 | AC | 771 ms
76,688 KB |
testcase_10 | AC | 652 ms
72,264 KB |
testcase_11 | AC | 1,111 ms
97,596 KB |
testcase_12 | AC | 846 ms
80,656 KB |
testcase_13 | AC | 970 ms
91,636 KB |
testcase_14 | AC | 346 ms
63,100 KB |
testcase_15 | AC | 54 ms
50,168 KB |
testcase_16 | AC | 53 ms
50,504 KB |
testcase_17 | AC | 54 ms
50,404 KB |
testcase_18 | AC | 922 ms
81,340 KB |
testcase_19 | AC | 634 ms
71,544 KB |
testcase_20 | AC | 1,286 ms
103,720 KB |
testcase_21 | AC | 1,299 ms
100,064 KB |
testcase_22 | AC | 712 ms
75,860 KB |
testcase_23 | AC | 1,025 ms
93,032 KB |
testcase_24 | AC | 1,001 ms
89,660 KB |
testcase_25 | AC | 537 ms
68,076 KB |
testcase_26 | AC | 1,308 ms
105,584 KB |
testcase_27 | AC | 982 ms
95,608 KB |
testcase_28 | AC | 171 ms
57,908 KB |
testcase_29 | AC | 218 ms
61,628 KB |
testcase_30 | AC | 411 ms
73,120 KB |
testcase_31 | AC | 732 ms
75,664 KB |
testcase_32 | AC | 1,249 ms
112,512 KB |
testcase_33 | AC | 1,127 ms
99,168 KB |
testcase_34 | AC | 94 ms
51,412 KB |
testcase_35 | AC | 89 ms
51,172 KB |
testcase_36 | AC | 608 ms
74,096 KB |
testcase_37 | AC | 617 ms
75,680 KB |
testcase_38 | AC | 854 ms
89,960 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int count = sc.nextInt(); int start = sc.nextInt(); int limit = start + sc.nextInt(); List<List<Path>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int c = sc.nextInt(); graph.get(a).add(new Path(b, c)); graph.get(b).add(new Path(a, c)); } boolean[] hasRest = new boolean[n]; while (count-- > 0) { hasRest[sc.nextInt() - 1] = true; } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); long[][] costs = new long[2][n]; for (long[] arr : costs) { Arrays.fill(arr, Long.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.type][p.idx] <= p.value) { continue; } costs[p.type][p.idx] = p.value; if (p.type == 0 && hasRest[p.idx] && p.value <= limit) { queue.add(new Path(1, p.idx, Math.max(start, p.value) + 1)); } for (Path x : graph.get(p.idx)) { queue.add(new Path(p.type, x.idx, p.value + x.value)); } } System.out.println(costs[1][n - 1] == Long.MAX_VALUE ? -1 : costs[1][n - 1]); } static class Path implements Comparable<Path> { int type; int idx; long value; public Path(int type, int idx, long value) { this.type = type; this.idx = idx; this.value = value; } public Path(int idx, long value) { this(0, idx, value); } public int compareTo(Path another) { return Long.compare(value, another.value); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }