結果
問題 | No.92 逃走経路 |
ユーザー | tenten |
提出日時 | 2022-07-29 08:22:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 270 ms / 5,000 ms |
コード長 | 2,318 bytes |
コンパイル時間 | 4,692 ms |
コンパイル使用メモリ | 75,896 KB |
実行使用メモリ | 61,280 KB |
最終ジャッジ日時 | 2023-09-26 04:45:26 |
合計ジャッジ時間 | 9,410 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 198 ms
59,252 KB |
testcase_01 | AC | 45 ms
49,504 KB |
testcase_02 | AC | 46 ms
49,456 KB |
testcase_03 | AC | 45 ms
49,388 KB |
testcase_04 | AC | 45 ms
47,876 KB |
testcase_05 | AC | 207 ms
57,252 KB |
testcase_06 | AC | 183 ms
54,792 KB |
testcase_07 | AC | 191 ms
57,024 KB |
testcase_08 | AC | 64 ms
51,124 KB |
testcase_09 | AC | 159 ms
55,588 KB |
testcase_10 | AC | 261 ms
61,280 KB |
testcase_11 | AC | 265 ms
60,164 KB |
testcase_12 | AC | 270 ms
59,616 KB |
testcase_13 | AC | 140 ms
55,916 KB |
testcase_14 | AC | 152 ms
56,364 KB |
testcase_15 | AC | 171 ms
57,112 KB |
testcase_16 | AC | 176 ms
57,944 KB |
testcase_17 | AC | 196 ms
56,572 KB |
testcase_18 | AC | 188 ms
59,216 KB |
testcase_19 | AC | 192 ms
55,988 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); TreeSet<Integer> current = new TreeSet<>(); ArrayList<ArrayList<Path>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { current.add(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)); } while (k-- > 0) { int x = sc.nextInt(); TreeSet<Integer> next = new TreeSet(); for (int y : current) { for (Path z : graph.get(y)) { if (z.value == x) { next.add(z.idx); } } } current = next; } StringBuilder sb = new StringBuilder(); sb.append(current.size()).append("\n"); boolean isFirst = true; for (int x : current) { if (!isFirst) { sb.append(" "); } isFirst = false; sb.append(x + 1); } System.out.println(sb); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }