結果
問題 | No.1480 Many Complete Graphs |
ユーザー | tenten |
提出日時 | 2023-06-22 16:19:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 765 ms / 2,000 ms |
コード長 | 3,500 bytes |
コンパイル時間 | 3,170 ms |
コンパイル使用メモリ | 91,424 KB |
実行使用メモリ | 82,704 KB |
最終ジャッジ日時 | 2024-06-29 23:26:15 |
合計ジャッジ時間 | 32,175 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,316 KB |
testcase_01 | AC | 52 ms
37,108 KB |
testcase_02 | AC | 52 ms
37,316 KB |
testcase_03 | AC | 53 ms
37,292 KB |
testcase_04 | AC | 52 ms
37,160 KB |
testcase_05 | AC | 52 ms
37,032 KB |
testcase_06 | AC | 52 ms
37,152 KB |
testcase_07 | AC | 51 ms
37,192 KB |
testcase_08 | AC | 54 ms
37,180 KB |
testcase_09 | AC | 90 ms
38,984 KB |
testcase_10 | AC | 99 ms
39,128 KB |
testcase_11 | AC | 62 ms
37,216 KB |
testcase_12 | AC | 80 ms
38,052 KB |
testcase_13 | AC | 196 ms
49,676 KB |
testcase_14 | AC | 170 ms
46,068 KB |
testcase_15 | AC | 343 ms
53,512 KB |
testcase_16 | AC | 267 ms
51,184 KB |
testcase_17 | AC | 261 ms
51,068 KB |
testcase_18 | AC | 155 ms
46,484 KB |
testcase_19 | AC | 282 ms
50,964 KB |
testcase_20 | AC | 331 ms
52,468 KB |
testcase_21 | AC | 197 ms
50,300 KB |
testcase_22 | AC | 159 ms
46,132 KB |
testcase_23 | AC | 351 ms
56,072 KB |
testcase_24 | AC | 465 ms
56,640 KB |
testcase_25 | AC | 514 ms
61,356 KB |
testcase_26 | AC | 501 ms
70,024 KB |
testcase_27 | AC | 493 ms
56,728 KB |
testcase_28 | AC | 521 ms
70,384 KB |
testcase_29 | AC | 547 ms
66,724 KB |
testcase_30 | AC | 509 ms
66,828 KB |
testcase_31 | AC | 537 ms
67,948 KB |
testcase_32 | AC | 534 ms
67,304 KB |
testcase_33 | AC | 524 ms
67,180 KB |
testcase_34 | AC | 525 ms
67,184 KB |
testcase_35 | AC | 526 ms
67,084 KB |
testcase_36 | AC | 531 ms
66,580 KB |
testcase_37 | AC | 534 ms
67,076 KB |
testcase_38 | AC | 510 ms
66,448 KB |
testcase_39 | AC | 561 ms
68,188 KB |
testcase_40 | AC | 546 ms
67,792 KB |
testcase_41 | AC | 535 ms
66,452 KB |
testcase_42 | AC | 522 ms
67,036 KB |
testcase_43 | AC | 541 ms
66,740 KB |
testcase_44 | AC | 517 ms
66,948 KB |
testcase_45 | AC | 509 ms
70,680 KB |
testcase_46 | AC | 542 ms
67,248 KB |
testcase_47 | AC | 703 ms
72,080 KB |
testcase_48 | AC | 687 ms
70,956 KB |
testcase_49 | AC | 681 ms
80,712 KB |
testcase_50 | AC | 447 ms
67,088 KB |
testcase_51 | AC | 677 ms
70,764 KB |
testcase_52 | AC | 716 ms
82,348 KB |
testcase_53 | AC | 689 ms
78,924 KB |
testcase_54 | AC | 730 ms
71,236 KB |
testcase_55 | AC | 765 ms
82,704 KB |
testcase_56 | AC | 644 ms
69,268 KB |
testcase_57 | AC | 551 ms
76,564 KB |
testcase_58 | AC | 540 ms
78,100 KB |
evil_aftercontest.txt | AC | 947 ms
97,640 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(); ArrayList<ArrayList<Path>> graph = new ArrayList<>(); for (int i = 0; i < n + m * 2; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int k = sc.nextInt(); int c = sc.nextInt(); for (int j = 0; j < k; j++) { int x = sc.nextInt(); if (x % 2 == 0) { graph.get(x - 1).add(new Path(n + i * 2, x / 2 + c)); graph.get(n + i * 2).add(new Path(x - 1, x / 2)); } else { graph.get(x - 1).add(new Path(n + i * 2 + 1, x / 2 + c)); graph.get(n + i * 2 + 1).add(new Path(x - 1, x / 2 + 1)); } } graph.get(n + i * 2).add(new Path(n + i * 2 + 1, 0)); graph.get(n + i * 2 + 1).add(new Path(n + i * 2, 1)); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); long[] costs = new long[n + m * 2]; Arrays.fill(costs, Long.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, p.value + x.value)); } } if (costs[n - 1] == Long.MAX_VALUE) { System.out.println(-1); } else { System.out.println(costs[n - 1]); } } static class Path implements Comparable<Path> { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } } 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(); } }