結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | tenten |
提出日時 | 2023-03-28 08:44:07 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 892 ms / 2,000 ms |
コード長 | 3,210 bytes |
コンパイル時間 | 3,320 ms |
コンパイル使用メモリ | 94,268 KB |
実行使用メモリ | 81,476 KB |
最終ジャッジ日時 | 2024-09-20 00:16:56 |
合計ジャッジ時間 | 17,350 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
52,340 KB |
testcase_01 | AC | 50 ms
50,444 KB |
testcase_02 | AC | 51 ms
50,568 KB |
testcase_03 | AC | 51 ms
50,488 KB |
testcase_04 | AC | 51 ms
50,448 KB |
testcase_05 | AC | 50 ms
50,512 KB |
testcase_06 | AC | 50 ms
50,212 KB |
testcase_07 | AC | 51 ms
50,188 KB |
testcase_08 | AC | 49 ms
50,372 KB |
testcase_09 | AC | 124 ms
53,028 KB |
testcase_10 | AC | 81 ms
51,808 KB |
testcase_11 | AC | 122 ms
52,100 KB |
testcase_12 | AC | 157 ms
55,392 KB |
testcase_13 | AC | 187 ms
55,180 KB |
testcase_14 | AC | 254 ms
57,300 KB |
testcase_15 | AC | 70 ms
50,904 KB |
testcase_16 | AC | 88 ms
51,632 KB |
testcase_17 | AC | 82 ms
51,492 KB |
testcase_18 | AC | 66 ms
50,732 KB |
testcase_19 | AC | 77 ms
51,312 KB |
testcase_20 | AC | 278 ms
58,912 KB |
testcase_21 | AC | 167 ms
55,412 KB |
testcase_22 | AC | 378 ms
61,236 KB |
testcase_23 | AC | 304 ms
61,176 KB |
testcase_24 | AC | 455 ms
64,600 KB |
testcase_25 | AC | 504 ms
65,252 KB |
testcase_26 | AC | 710 ms
72,488 KB |
testcase_27 | AC | 830 ms
75,264 KB |
testcase_28 | AC | 861 ms
78,576 KB |
testcase_29 | AC | 892 ms
75,512 KB |
testcase_30 | AC | 449 ms
72,156 KB |
testcase_31 | AC | 533 ms
81,476 KB |
testcase_32 | AC | 266 ms
57,212 KB |
testcase_33 | AC | 105 ms
51,916 KB |
testcase_34 | AC | 79 ms
51,608 KB |
testcase_35 | AC | 153 ms
56,620 KB |
testcase_36 | AC | 156 ms
55,564 KB |
testcase_37 | AC | 138 ms
52,308 KB |
testcase_38 | AC | 348 ms
61,536 KB |
testcase_39 | AC | 183 ms
56,012 KB |
testcase_40 | AC | 234 ms
56,992 KB |
testcase_41 | AC | 270 ms
59,596 KB |
testcase_42 | AC | 232 ms
59,580 KB |
testcase_43 | AC | 232 ms
57,000 KB |
testcase_44 | AC | 460 ms
65,132 KB |
testcase_45 | AC | 153 ms
53,256 KB |
testcase_46 | AC | 372 ms
61,308 KB |
ソースコード
import java.io.*; import java.util.*; 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 k = sc.nextInt(); HashMap<Integer, Integer> idxes = new HashMap<>(); for (int i = 0; i < k; i++) { idxes.put(sc.nextInt() - 1, i); } ArrayList<ArrayList<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(); int uri = 0; if (idxes.containsKey(i)) { uri = (1 << idxes.get(i)); } graph.get(a).add(new Path(b, c, uri)); graph.get(b).add(new Path(a, c, uri)); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); int[][] costs = new int[1 << k][n]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.uri][p.idx] <= p.value) { continue; } costs[p.uri][p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, p.value + x.value, p.uri | x.uri)); } } System.out.println(costs[(1 << k) - 1][n - 1]); } static class Path implements Comparable<Path> { int idx; int value; int uri; public Path(int idx, int value, int uri) { this.idx = idx; this.value = value; this.uri = uri; } public int compareTo(Path another) { return value - another.value; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }