結果

問題 No.812 Change of Class
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-04-15 23:16:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 4,000 ms
コード長 1,277 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 100,396 KB
実行使用メモリ 9,520 KB
最終ジャッジ日時 2023-09-03 15:09:15
合計ジャッジ時間 7,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
8,164 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 40 ms
6,004 KB
testcase_03 AC 86 ms
9,080 KB
testcase_04 AC 76 ms
8,296 KB
testcase_05 AC 183 ms
8,164 KB
testcase_06 AC 155 ms
7,172 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 169 ms
9,080 KB
testcase_10 AC 173 ms
9,020 KB
testcase_11 AC 22 ms
6,920 KB
testcase_12 AC 118 ms
8,300 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 115 ms
6,996 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 112 ms
7,488 KB
testcase_18 AC 85 ms
6,340 KB
testcase_19 AC 96 ms
6,660 KB
testcase_20 AC 176 ms
8,524 KB
testcase_21 AC 81 ms
6,176 KB
testcase_22 AC 36 ms
4,508 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 11 ms
4,504 KB
testcase_25 AC 29 ms
4,380 KB
testcase_26 AC 145 ms
8,116 KB
testcase_27 AC 128 ms
7,620 KB
testcase_28 AC 91 ms
6,572 KB
testcase_29 AC 21 ms
4,376 KB
testcase_30 AC 114 ms
7,380 KB
testcase_31 AC 100 ms
6,668 KB
testcase_32 AC 46 ms
4,772 KB
testcase_33 AC 123 ms
7,944 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 24 ms
4,380 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 53 ms
5,448 KB
testcase_38 AC 9 ms
4,756 KB
testcase_39 AC 55 ms
5,392 KB
testcase_40 AC 15 ms
4,380 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 111 ms
7,184 KB
testcase_43 AC 34 ms
6,208 KB
testcase_44 AC 77 ms
6,112 KB
testcase_45 AC 9 ms
4,376 KB
testcase_46 AC 32 ms
6,232 KB
testcase_47 AC 76 ms
6,112 KB
testcase_48 AC 87 ms
6,936 KB
testcase_49 AC 22 ms
4,392 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 27 ms
4,500 KB
testcase_52 AC 55 ms
6,416 KB
testcase_53 AC 15 ms
4,380 KB
testcase_54 AC 13 ms
4,376 KB
testcase_55 AC 57 ms
7,620 KB
testcase_56 AC 68 ms
8,468 KB
testcase_57 AC 71 ms
8,944 KB
testcase_58 AC 37 ms
6,028 KB
testcase_59 AC 80 ms
9,520 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>

int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<int>> nxts(n, std::vector<int>());
    for (int i = 0; i < m; i++) {
        int p, q;
        std::cin >> p >> q;
        p--;
        q--;
        nxts[p].push_back(q);
        nxts[q].push_back(p);
    }

    int q;
    std::cin >> q;

    for (int i = 0; i < q; i++) {
        int a;
        std::cin >> a;
        a--;

        int inf = 1000000007;
        std::vector<int> d(n, inf);
        d[a] = 0;
        std::queue<int> que;
        que.push(a);
        while(!que.empty()){
            int x = que.front();
            que.pop();
            for (auto&& y : nxts[x]) {
                if (d[x] + 1 < d[y]) {
                    d[y] = d[x] + 1;
                    que.push(y); 
                }
            }
        }

        int b = 0;
        int c = 0;
        for (auto&& v : d) {
            if (v != 0 && v != inf) {
                b++;
                c = std::max(c, v);
            }
        }

        if (c == 0) {
            std::cout << b << " " << c << std::endl;
        } else {
            std::cout << b << " " << std::ceil(std::log2(c)) << std::endl;
        }
    }
} 
0