結果
問題 | No.1480 Many Complete Graphs |
ユーザー | tenten |
提出日時 | 2022-09-02 18:54:10 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 699 ms / 2,000 ms |
コード長 | 2,786 bytes |
コンパイル時間 | 1,890 ms |
コンパイル使用メモリ | 79,160 KB |
実行使用メモリ | 88,072 KB |
最終ジャッジ日時 | 2024-04-27 18:47:10 |
合計ジャッジ時間 | 26,173 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,300 KB |
testcase_01 | AC | 47 ms
50,428 KB |
testcase_02 | AC | 45 ms
49,952 KB |
testcase_03 | AC | 47 ms
49,936 KB |
testcase_04 | AC | 46 ms
50,416 KB |
testcase_05 | AC | 47 ms
50,044 KB |
testcase_06 | AC | 47 ms
50,072 KB |
testcase_07 | AC | 45 ms
50,296 KB |
testcase_08 | AC | 47 ms
50,332 KB |
testcase_09 | AC | 85 ms
51,336 KB |
testcase_10 | AC | 79 ms
51,600 KB |
testcase_11 | AC | 53 ms
50,372 KB |
testcase_12 | AC | 59 ms
51,152 KB |
testcase_13 | AC | 170 ms
59,364 KB |
testcase_14 | AC | 142 ms
58,328 KB |
testcase_15 | AC | 296 ms
63,224 KB |
testcase_16 | AC | 232 ms
60,620 KB |
testcase_17 | AC | 242 ms
60,496 KB |
testcase_18 | AC | 124 ms
56,856 KB |
testcase_19 | AC | 246 ms
60,504 KB |
testcase_20 | AC | 271 ms
62,060 KB |
testcase_21 | AC | 166 ms
59,072 KB |
testcase_22 | AC | 145 ms
57,744 KB |
testcase_23 | AC | 278 ms
67,764 KB |
testcase_24 | AC | 409 ms
66,640 KB |
testcase_25 | AC | 453 ms
71,284 KB |
testcase_26 | AC | 563 ms
74,188 KB |
testcase_27 | AC | 406 ms
66,312 KB |
testcase_28 | AC | 451 ms
76,004 KB |
testcase_29 | AC | 457 ms
76,448 KB |
testcase_30 | AC | 461 ms
76,180 KB |
testcase_31 | AC | 450 ms
76,272 KB |
testcase_32 | AC | 462 ms
75,904 KB |
testcase_33 | AC | 477 ms
75,720 KB |
testcase_34 | AC | 465 ms
76,200 KB |
testcase_35 | AC | 461 ms
76,380 KB |
testcase_36 | AC | 449 ms
75,812 KB |
testcase_37 | AC | 451 ms
76,124 KB |
testcase_38 | AC | 448 ms
76,216 KB |
testcase_39 | AC | 468 ms
76,372 KB |
testcase_40 | AC | 494 ms
75,896 KB |
testcase_41 | AC | 452 ms
75,940 KB |
testcase_42 | AC | 454 ms
75,960 KB |
testcase_43 | AC | 457 ms
76,012 KB |
testcase_44 | AC | 461 ms
76,504 KB |
testcase_45 | AC | 483 ms
76,452 KB |
testcase_46 | AC | 471 ms
76,332 KB |
testcase_47 | AC | 562 ms
80,096 KB |
testcase_48 | AC | 579 ms
80,264 KB |
testcase_49 | AC | 698 ms
80,392 KB |
testcase_50 | AC | 374 ms
75,508 KB |
testcase_51 | AC | 699 ms
80,656 KB |
testcase_52 | AC | 573 ms
68,624 KB |
testcase_53 | AC | 556 ms
68,924 KB |
testcase_54 | AC | 541 ms
68,544 KB |
testcase_55 | AC | 529 ms
68,680 KB |
testcase_56 | AC | 536 ms
68,668 KB |
testcase_57 | AC | 501 ms
88,072 KB |
testcase_58 | AC | 469 ms
68,408 KB |
evil_aftercontest.txt | AC | 998 ms
106,396 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(); 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() - 1; int idx = n + i * 2 + x % 2; graph.get(x).add(new Path(idx, c + x + 1)); graph.get(idx).add(new Path(x, c + x + 1)); } graph.get(n + i * 2).add(new Path(n + i * 2 + 1, 1)); graph.get(n + i * 2 + 1).add(new Path(n + i * 2, 1)); } long[] costs = new long[n + m * 2]; PriorityQueue<Path> queue = new PriorityQueue<>(); Arrays.fill(costs, Long.MAX_VALUE); queue.add(new Path(0, 0)); 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] / 2); } } 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 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }