結果
問題 | No.1812 Uribo Road |
ユーザー | tenten |
提出日時 | 2022-01-20 13:53:20 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,981 bytes |
コンパイル時間 | 2,685 ms |
コンパイル使用メモリ | 79,992 KB |
実行使用メモリ | 331,080 KB |
最終ジャッジ日時 | 2024-05-02 22:37:47 |
合計ジャッジ時間 | 10,745 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
42,272 KB |
testcase_01 | AC | 49 ms
36,816 KB |
testcase_02 | AC | 48 ms
36,864 KB |
testcase_03 | AC | 177 ms
45,648 KB |
testcase_04 | AC | 49 ms
36,636 KB |
testcase_05 | AC | 48 ms
37,028 KB |
testcase_06 | AC | 51 ms
37,000 KB |
testcase_07 | AC | 52 ms
37,028 KB |
testcase_08 | AC | 222 ms
47,060 KB |
testcase_09 | AC | 310 ms
49,756 KB |
testcase_10 | AC | 186 ms
45,648 KB |
testcase_11 | AC | 158 ms
43,392 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
ソースコード
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(); HashMap<Integer, Integer> idxes = new HashMap<>(); for (int i = 0; i < k; i++) { idxes.put(sc.nextInt() - 1, i); } ArrayList<ArrayList<Road>> 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 Road(b, c, idxes.getOrDefault(i, -1))); graph.get(b).add(new Road(a, c, idxes.getOrDefault(i, -1))); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); int[][] cost = new int[1 << k][n]; for (int[] arr : cost) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (cost[p.mask][p.idx] <= p.value) { continue; } cost[p.mask][p.idx] = p.value; for (Road x : graph.get(p.idx)) { if (x.mask >= 0) { queue.add(new Path(x.idx, p.value + x.cost, p.mask | (1 << x.mask))); } else { queue.add(new Path(x.idx, p.value + x.cost, p.mask)); } } } System.out.println(cost[(1 << k) - 1][n - 1]); } static class Path implements Comparable<Path> { int idx; int value; int mask; public Path(int idx, int value, int mask) { this.idx = idx; this.value = value; this.mask = mask; } public int compareTo(Path another) { return value - another.value; } } static class Road { int idx; int cost; int mask; public Road(int idx, int cost, int mask) { this.idx = idx; this.cost = cost; this.mask = mask; } } } 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 { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }