結果
問題 |
No.92 逃走経路
|
ユーザー |
![]() |
提出日時 | 2020-11-17 17:52:31 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 445 ms / 5,000 ms |
コード長 | 1,895 bytes |
コンパイル時間 | 2,756 ms |
コンパイル使用メモリ | 79,668 KB |
実行使用メモリ | 62,008 KB |
最終ジャッジ日時 | 2024-07-23 08:23:25 |
合計ジャッジ時間 | 9,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); HashMap<Integer, HashMap<Integer, ArrayList<Integer>>> route = new HashMap<>(); for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if (!route.containsKey(c)) { route.put(c, new HashMap<>()); } if (!route.get(c).containsKey(a)) { route.get(c).put(a, new ArrayList<>()); } route.get(c).get(a).add(b); if (!route.get(c).containsKey(b)) { route.get(c).put(b, new ArrayList<>()); } route.get(c).get(b).add(a); } ArrayList<TreeSet<Integer>> currents = new ArrayList<>(); for (int i = 0; i <= k; i++) { currents.add(new TreeSet<>()); } for (int i = 1; i <= n; i++) { currents.get(0).add(i); } for (int i = 0; i < k; i++) { int x = sc.nextInt(); HashMap<Integer, ArrayList<Integer>> tmp = route.get(x); if (tmp == null) { break; } for (int y : currents.get(i)) { if (tmp.containsKey(y)) { currents.get(i + 1).addAll(tmp.get(y)); } } } StringBuilder sb = new StringBuilder(); sb.append(currents.get(k).size()).append("\n"); boolean isFirst = true; for (int x : currents.get(k)) { if (isFirst) { isFirst = false; } else { sb.append(" "); } sb.append(x); } System.out.println(sb); } }