結果

問題 No.812 Change of Class
ユーザー tentententen
提出日時 2022-04-21 16:17:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,703 bytes
コンパイル時間 3,463 ms
コンパイル使用メモリ 77,496 KB
実行使用メモリ 90,988 KB
最終ジャッジ日時 2023-09-04 22:17:01
合計ジャッジ時間 76,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 852 ms
58,864 KB
testcase_01 AC 307 ms
47,488 KB
testcase_02 AC 628 ms
50,508 KB
testcase_03 AC 1,006 ms
68,700 KB
testcase_04 AC 805 ms
67,568 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 66 ms
36,668 KB
testcase_08 AC 60 ms
35,452 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 220 ms
65,444 KB
testcase_12 WA -
testcase_13 AC 46 ms
49,784 KB
testcase_14 AC 47 ms
49,720 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 577 ms
68,740 KB
testcase_36 AC 335 ms
61,684 KB
testcase_37 AC 1,038 ms
64,384 KB
testcase_38 AC 125 ms
55,244 KB
testcase_39 AC 1,020 ms
64,328 KB
testcase_40 AC 405 ms
62,176 KB
testcase_41 AC 116 ms
54,684 KB
testcase_42 AC 1,750 ms
66,808 KB
testcase_43 AC 403 ms
63,560 KB
testcase_44 AC 1,354 ms
64,536 KB
testcase_45 AC 330 ms
62,424 KB
testcase_46 AC 356 ms
63,032 KB
testcase_47 AC 1,356 ms
64,668 KB
testcase_48 AC 1,224 ms
67,272 KB
testcase_49 AC 682 ms
62,892 KB
testcase_50 AC 151 ms
57,152 KB
testcase_51 AC 581 ms
62,840 KB
testcase_52 AC 751 ms
63,416 KB
testcase_53 AC 482 ms
64,488 KB
testcase_54 AC 455 ms
64,116 KB
testcase_55 AC 1,166 ms
82,076 KB
testcase_56 AC 1,440 ms
89,816 KB
testcase_57 AC 1,371 ms
85,704 KB
testcase_58 AC 886 ms
70,968 KB
testcase_59 AC 1,478 ms
90,988 KB
testcase_60 AC 45 ms
49,972 KB
testcase_61 AC 45 ms
49,676 KB
testcase_62 AC 45 ms
50,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        }
        int q = sc.nextInt();
        int[] costs = new int[n];
        PriorityQueue<Path> queue = new PriorityQueue<>();
        TreeMap<Integer, Integer> days = new TreeMap<>();
        int value = 1;
        for (int i = 0; i < 30; i++) {
            days.put(value, i);
            value *= 2;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt() - 1;
            Arrays.fill(costs, Integer.MAX_VALUE);
            queue.add(new Path(x, 0));
            int max = 0;
            int count = 0;
            while (queue.size() > 0) {
                Path p = queue.poll();
                if (costs[p.idx] < p.value) {
                    continue;
                }
                costs[p.idx] = p.value;
                max = p.value;
                count++;
                for (int y : graph.get(p.idx)) {
                    queue.add(new Path(y, p.value + 1));
                }
            }
            sb.append(count - 1).append(" ").append(days.ceilingEntry(max).getValue()).append("\n");
        }
        System.out.print(sb);
    }
    
    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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0