結果
問題 | No.1190 Points |
ユーザー | tenten |
提出日時 | 2020-08-24 22:37:18 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,553 bytes |
コンパイル時間 | 2,392 ms |
コンパイル使用メモリ | 80,640 KB |
実行使用メモリ | 84,548 KB |
最終ジャッジ日時 | 2024-04-24 03:57:43 |
合計ジャッジ時間 | 37,144 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
41,664 KB |
testcase_01 | AC | 120 ms
41,224 KB |
testcase_02 | AC | 126 ms
41,472 KB |
testcase_03 | AC | 1,237 ms
70,752 KB |
testcase_04 | AC | 1,229 ms
67,196 KB |
testcase_05 | AC | 1,028 ms
65,728 KB |
testcase_06 | AC | 1,465 ms
73,420 KB |
testcase_07 | AC | 1,531 ms
75,880 KB |
testcase_08 | AC | 1,321 ms
74,340 KB |
testcase_09 | AC | 1,384 ms
78,588 KB |
testcase_10 | AC | 1,286 ms
75,468 KB |
testcase_11 | AC | 1,443 ms
73,140 KB |
testcase_12 | AC | 1,401 ms
74,636 KB |
testcase_13 | AC | 1,428 ms
73,632 KB |
testcase_14 | WA | - |
testcase_15 | AC | 1,714 ms
77,624 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 1,481 ms
73,948 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1,808 ms
79,452 KB |
testcase_24 | TLE | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
ソースコード
import java.util.*; public class Main { static final int MAX = Integer.MAX_VALUE / 10; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int pp = sc.nextInt(); int s = sc.nextInt() - 1; int g = sc.nextInt() - 1; ArrayList<ArrayList<Integer>> 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; graph.get(a).add(b); graph.get(b).add(a); } int[][] costsS = new int[2][n]; int[][] costsG = new int[2][n]; Arrays.fill(costsS[0], MAX); Arrays.fill(costsS[1], MAX); Arrays.fill(costsG[0], MAX); Arrays.fill(costsG[1], MAX); PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(s, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costsS[p.value % 2][p.idx] <= p.value) { continue; } costsS[p.value % 2][p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } queue.add(new Path(g, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costsG[p.value % 2][p.idx] <= p.value) { continue; } costsG[p.value % 2][p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 0; i < n; i++) { if (costsS[0][i] + costsG[pp % 2][i] <= pp || costsS[1][i] + costsG[(pp + 1) % 2][i] <= pp) { ans.add(i + 1); } } if (ans.size() == 0) { System.out.println(-1); } else { StringBuilder sb = new StringBuilder(); sb.append(ans.size()).append("\n"); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }