結果
問題 | No.1480 Many Complete Graphs |
ユーザー | tenten |
提出日時 | 2021-04-28 16:26:24 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 773 ms / 2,000 ms |
コード長 | 2,620 bytes |
コンパイル時間 | 2,476 ms |
コンパイル使用メモリ | 75,868 KB |
実行使用メモリ | 113,660 KB |
最終ジャッジ日時 | 2023-09-21 20:46:55 |
合計ジャッジ時間 | 32,340 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
49,492 KB |
testcase_01 | AC | 42 ms
49,548 KB |
testcase_02 | AC | 43 ms
50,068 KB |
testcase_03 | AC | 42 ms
49,492 KB |
testcase_04 | AC | 43 ms
49,580 KB |
testcase_05 | AC | 43 ms
49,524 KB |
testcase_06 | AC | 43 ms
49,600 KB |
testcase_07 | AC | 42 ms
49,492 KB |
testcase_08 | AC | 47 ms
49,700 KB |
testcase_09 | AC | 85 ms
51,552 KB |
testcase_10 | AC | 80 ms
51,412 KB |
testcase_11 | AC | 57 ms
51,232 KB |
testcase_12 | AC | 72 ms
51,264 KB |
testcase_13 | AC | 209 ms
66,100 KB |
testcase_14 | AC | 173 ms
60,344 KB |
testcase_15 | AC | 357 ms
68,724 KB |
testcase_16 | AC | 227 ms
63,036 KB |
testcase_17 | AC | 242 ms
63,420 KB |
testcase_18 | AC | 145 ms
58,488 KB |
testcase_19 | AC | 248 ms
63,408 KB |
testcase_20 | AC | 345 ms
66,172 KB |
testcase_21 | AC | 226 ms
65,236 KB |
testcase_22 | AC | 164 ms
59,912 KB |
testcase_23 | AC | 461 ms
89,392 KB |
testcase_24 | AC | 516 ms
78,172 KB |
testcase_25 | AC | 597 ms
84,784 KB |
testcase_26 | AC | 737 ms
104,420 KB |
testcase_27 | AC | 513 ms
78,260 KB |
testcase_28 | AC | 554 ms
92,680 KB |
testcase_29 | AC | 537 ms
92,672 KB |
testcase_30 | AC | 598 ms
93,316 KB |
testcase_31 | AC | 526 ms
93,192 KB |
testcase_32 | AC | 548 ms
92,900 KB |
testcase_33 | AC | 565 ms
92,828 KB |
testcase_34 | AC | 576 ms
92,952 KB |
testcase_35 | AC | 539 ms
92,656 KB |
testcase_36 | AC | 514 ms
90,940 KB |
testcase_37 | AC | 524 ms
92,832 KB |
testcase_38 | AC | 560 ms
92,904 KB |
testcase_39 | AC | 544 ms
94,884 KB |
testcase_40 | AC | 522 ms
93,312 KB |
testcase_41 | AC | 525 ms
93,060 KB |
testcase_42 | AC | 538 ms
90,760 KB |
testcase_43 | AC | 539 ms
92,592 KB |
testcase_44 | AC | 533 ms
92,860 KB |
testcase_45 | AC | 535 ms
91,648 KB |
testcase_46 | AC | 528 ms
92,832 KB |
testcase_47 | AC | 663 ms
100,896 KB |
testcase_48 | AC | 691 ms
99,672 KB |
testcase_49 | AC | 667 ms
99,524 KB |
testcase_50 | AC | 389 ms
84,640 KB |
testcase_51 | AC | 695 ms
99,204 KB |
testcase_52 | AC | 674 ms
100,812 KB |
testcase_53 | AC | 670 ms
100,796 KB |
testcase_54 | AC | 773 ms
100,724 KB |
testcase_55 | AC | 754 ms
100,512 KB |
testcase_56 | AC | 766 ms
113,660 KB |
testcase_57 | AC | 482 ms
100,912 KB |
testcase_58 | AC | 516 ms
82,428 KB |
evil_aftercontest.txt | AC | 949 ms
124,888 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<HashMap<Integer, Integer>> graph = new ArrayList<>(); for (int i = 0; i < n + m; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int k = sc.nextInt(); int c = sc.nextInt() * 2; for (int j = 0; j < k; j++) { int x = sc.nextInt() - 1; graph.get(x).put(n + i, c + x + 1); graph.get(n + i).put(x, x + 1); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); long[] costs = new long[n + m]; Arrays.fill(costs, Long.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (p.idx < n && p.value % 2 == 1) { p.value++; } if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx).keySet()) { if (costs[x] == Long.MAX_VALUE) { queue.add(new Path(x, p.value + graph.get(p.idx).get(x))); } } } 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(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }