結果
問題 | No.812 Change of Class |
ユーザー | tenten |
提出日時 | 2022-08-12 11:05:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,291 ms / 4,000 ms |
コード長 | 2,792 bytes |
コンパイル時間 | 2,415 ms |
コンパイル使用メモリ | 80,844 KB |
実行使用メモリ | 89,112 KB |
最終ジャッジ日時 | 2024-09-22 14:30:53 |
合計ジャッジ時間 | 61,246 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 825 ms
75,952 KB |
testcase_01 | AC | 366 ms
59,500 KB |
testcase_02 | AC | 621 ms
63,720 KB |
testcase_03 | AC | 1,033 ms
82,308 KB |
testcase_04 | AC | 797 ms
75,408 KB |
testcase_05 | AC | 2,078 ms
79,028 KB |
testcase_06 | AC | 2,150 ms
82,632 KB |
testcase_07 | AC | 107 ms
41,392 KB |
testcase_08 | AC | 84 ms
39,436 KB |
testcase_09 | AC | 2,061 ms
68,888 KB |
testcase_10 | AC | 2,028 ms
68,844 KB |
testcase_11 | AC | 253 ms
55,052 KB |
testcase_12 | AC | 1,483 ms
65,984 KB |
testcase_13 | AC | 51 ms
37,000 KB |
testcase_14 | AC | 52 ms
37,116 KB |
testcase_15 | AC | 1,620 ms
64,116 KB |
testcase_16 | AC | 266 ms
49,748 KB |
testcase_17 | AC | 1,439 ms
67,424 KB |
testcase_18 | AC | 1,082 ms
54,464 KB |
testcase_19 | AC | 1,290 ms
59,980 KB |
testcase_20 | AC | 2,291 ms
82,104 KB |
testcase_21 | AC | 1,029 ms
63,288 KB |
testcase_22 | AC | 640 ms
62,232 KB |
testcase_23 | AC | 238 ms
59,072 KB |
testcase_24 | AC | 295 ms
61,408 KB |
testcase_25 | AC | 588 ms
61,960 KB |
testcase_26 | AC | 1,724 ms
71,752 KB |
testcase_27 | AC | 1,555 ms
74,932 KB |
testcase_28 | AC | 1,216 ms
70,324 KB |
testcase_29 | AC | 509 ms
59,748 KB |
testcase_30 | AC | 1,374 ms
73,500 KB |
testcase_31 | AC | 1,381 ms
69,620 KB |
testcase_32 | AC | 744 ms
62,492 KB |
testcase_33 | AC | 1,532 ms
76,912 KB |
testcase_34 | AC | 286 ms
61,140 KB |
testcase_35 | AC | 558 ms
62,396 KB |
testcase_36 | AC | 307 ms
61,152 KB |
testcase_37 | AC | 862 ms
63,420 KB |
testcase_38 | AC | 171 ms
55,712 KB |
testcase_39 | AC | 888 ms
63,524 KB |
testcase_40 | AC | 391 ms
59,504 KB |
testcase_41 | AC | 157 ms
55,816 KB |
testcase_42 | AC | 1,609 ms
70,940 KB |
testcase_43 | AC | 420 ms
63,384 KB |
testcase_44 | AC | 1,143 ms
63,716 KB |
testcase_45 | AC | 316 ms
61,504 KB |
testcase_46 | AC | 385 ms
63,244 KB |
testcase_47 | AC | 1,233 ms
65,356 KB |
testcase_48 | AC | 1,314 ms
71,952 KB |
testcase_49 | AC | 628 ms
63,008 KB |
testcase_50 | AC | 151 ms
56,220 KB |
testcase_51 | AC | 538 ms
62,008 KB |
testcase_52 | AC | 721 ms
63,592 KB |
testcase_53 | AC | 442 ms
59,984 KB |
testcase_54 | AC | 428 ms
60,144 KB |
testcase_55 | AC | 1,315 ms
83,520 KB |
testcase_56 | AC | 1,461 ms
89,112 KB |
testcase_57 | AC | 1,252 ms
88,476 KB |
testcase_58 | AC | 1,102 ms
66,352 KB |
testcase_59 | AC | 1,546 ms
84,360 KB |
testcase_60 | AC | 54 ms
50,036 KB |
testcase_61 | AC | 54 ms
50,444 KB |
testcase_62 | AC | 54 ms
50,592 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<Integer>> 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; graph.get(a).add(b); graph.get(b).add(a); } StringBuilder sb = new StringBuilder(); int q = sc.nextInt(); PriorityQueue<Path> queue = new PriorityQueue<>(); int[] days = new int[n]; while (q-- > 0) { int x = sc.nextInt() - 1; Arrays.fill(days, Integer.MAX_VALUE); queue.add(new Path(x, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (days[p.idx] <= p.value) { continue; } days[p.idx] = p.value; for (int y : graph.get(p.idx)) { queue.add(new Path(y, p.value + 1)); } } int count = -1; int max = 0; for (int y : days) { if (y < Integer.MAX_VALUE) { count++; max = Math.max(max, y); } } sb.append(count).append(" ").append(getDay(max)).append("\n"); } System.out.print(sb); } static int getDay(int d) { int day = 0; int base = 1; while (d > base) { day++; base *= 2; } return day; } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } 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 { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }