結果

問題 No.812 Change of Class
ユーザー polylogKpolylogK
提出日時 2019-04-12 22:53:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 4,000 ms
コード長 1,069 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 60,324 KB
実行使用メモリ 8,840 KB
最終ジャッジ日時 2023-09-03 13:55:51
合計ジャッジ時間 6,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
7,340 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 26 ms
5,040 KB
testcase_03 AC 56 ms
8,152 KB
testcase_04 AC 49 ms
7,532 KB
testcase_05 AC 130 ms
7,420 KB
testcase_06 AC 109 ms
6,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 120 ms
8,232 KB
testcase_10 AC 123 ms
8,216 KB
testcase_11 AC 13 ms
6,120 KB
testcase_12 AC 82 ms
7,924 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 86 ms
6,360 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 79 ms
6,688 KB
testcase_18 AC 60 ms
5,424 KB
testcase_19 AC 69 ms
5,856 KB
testcase_20 AC 126 ms
8,008 KB
testcase_21 AC 57 ms
5,260 KB
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 5 ms
4,384 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 105 ms
7,184 KB
testcase_27 AC 93 ms
6,644 KB
testcase_28 AC 66 ms
5,768 KB
testcase_29 AC 16 ms
4,380 KB
testcase_30 AC 86 ms
6,504 KB
testcase_31 AC 74 ms
5,740 KB
testcase_32 AC 33 ms
4,376 KB
testcase_33 AC 90 ms
7,032 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 17 ms
4,380 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 39 ms
4,516 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 42 ms
4,552 KB
testcase_40 AC 11 ms
4,380 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 86 ms
6,280 KB
testcase_43 AC 21 ms
5,448 KB
testcase_44 AC 58 ms
5,324 KB
testcase_45 AC 7 ms
4,376 KB
testcase_46 AC 19 ms
5,488 KB
testcase_47 AC 57 ms
5,308 KB
testcase_48 AC 66 ms
6,060 KB
testcase_49 AC 16 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 20 ms
4,376 KB
testcase_52 AC 40 ms
5,500 KB
testcase_53 AC 11 ms
4,376 KB
testcase_54 AC 10 ms
4,384 KB
testcase_55 AC 37 ms
6,992 KB
testcase_56 AC 43 ms
7,796 KB
testcase_57 AC 46 ms
8,116 KB
testcase_58 AC 24 ms
5,360 KB
testcase_59 AC 51 ms
8,840 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 1 ms
4,384 KB
testcase_62 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>

int main() {
    int n, m; scanf("%d%d", &n, &m);
    std::vector<std::vector<int>> g(n);
    for(int i = 0; i < m; i++) {
        int a, b; scanf("%d%d", &a, &b);

        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    int q; scanf("%d", &q);
    while(q--) {
        int s; scanf("%d", &s); s--;

        std::queue<int> qu; qu.push(s);
        std::vector<int> min_cost(n, 1 << 30); min_cost[s] = 0;
        while(!qu.empty()) {
            auto p = qu.front(); qu.pop();

            for(auto e: g[p]) {
                if(min_cost[p] + 1 >= min_cost[e]) continue;
                min_cost[e] = min_cost[p] + 1;
                qu.push(e);
            }
        }
        
        int ma = 0, count = 0;
        for(auto v: min_cost) {
            if(v == 1 << 30) continue;
            ma = std::max(ma, v - 1);
            count++;
        }

        int log = 0;
        while(ma >> log) log++;
        printf("%d %d\n", count - 1, log);
    }
    return 0;
}
0