結果
問題 | No.812 Change of Class |
ユーザー | neko_the_shadow |
提出日時 | 2019-04-15 22:24:43 |
言語 | Java19 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,107 bytes |
コンパイル時間 | 5,032 ms |
コンパイル使用メモリ | 98,676 KB |
実行使用メモリ | 103,596 KB |
最終ジャッジ日時 | 2023-09-03 15:28:13 |
合計ジャッジ時間 | 56,881 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,842 ms
96,952 KB |
testcase_01 | AC | 739 ms
68,704 KB |
testcase_02 | AC | 1,488 ms
80,544 KB |
testcase_03 | AC | 2,358 ms
103,596 KB |
testcase_04 | AC | 2,182 ms
95,752 KB |
testcase_05 | AC | 3,722 ms
97,048 KB |
testcase_06 | AC | 2,837 ms
90,580 KB |
testcase_07 | AC | 596 ms
73,056 KB |
testcase_08 | AC | 366 ms
63,368 KB |
testcase_09 | AC | 3,424 ms
102,300 KB |
testcase_10 | AC | 3,549 ms
102,524 KB |
testcase_11 | AC | 1,467 ms
85,644 KB |
testcase_12 | AC | 3,045 ms
99,820 KB |
testcase_13 | AC | 149 ms
55,988 KB |
testcase_14 | AC | 150 ms
55,928 KB |
testcase_15 | AC | 3,542 ms
86,392 KB |
testcase_16 | AC | 570 ms
65,984 KB |
testcase_17 | AC | 2,609 ms
91,376 KB |
testcase_18 | AC | 2,094 ms
86,216 KB |
testcase_19 | AC | 2,262 ms
87,768 KB |
testcase_20 | AC | 3,614 ms
102,660 KB |
testcase_21 | TLE | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
ソースコード
import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = stdin.nextInt(); int m = stdin.nextInt(); List<List<Integer>> friend = IntStream.range(0, n).mapToObj(unused -> new ArrayList<Integer>()).collect(Collectors.toList()); for (int i = 0; i < m; i++) { int p = stdin.nextInt() - 1; int q = stdin.nextInt() - 1; friend.get(p).add(q); friend.get(q).add(p); } int q = stdin.nextInt(); List<Integer> alist = new ArrayList<>(); for (int i = 0; i < q; i++) { int a = stdin.nextInt() - 1; alist.add(a); } int inf = 1000000007; for (int a : alist) { List<Integer> d = IntStream.range(0, n).map(unused -> inf).boxed().collect(Collectors.toList()); d.set(a, 0); PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.comparingInt(i -> d.get(i))); IntStream.range(0, n).forEach(i -> pq.offer(i)); while (!pq.isEmpty()) { int x = pq.poll(); for (int y : friend.get(x)) { if (d.get(x) + 1 < d.get(y)) { d.set(y, d.get(x) + 1); pq.offer(y); } } } int b = 0; int c = 0; for (int v : d) { if (v != 0 && v != inf) { b++; c = Math.max(c, v); } } if (c == 0) { System.out.printf("%d %d%n", b, c); } else { System.out.printf("%d %d%n", b, (int)Math.ceil(Math.log(c) / Math.log(2))); } } } }