結果

問題 No.812 Change of Class
ユーザー rpy3cpprpy3cpp
提出日時 2019-04-14 03:55:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 4,000 ms
コード長 1,241 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 171,716 KB
実行使用メモリ 9,744 KB
最終ジャッジ日時 2023-09-03 15:07:49
合計ジャッジ時間 6,881 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
7,788 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 27 ms
5,668 KB
testcase_03 AC 57 ms
8,564 KB
testcase_04 AC 50 ms
7,948 KB
testcase_05 AC 138 ms
8,252 KB
testcase_06 AC 120 ms
7,104 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 123 ms
8,796 KB
testcase_10 AC 124 ms
8,868 KB
testcase_11 AC 12 ms
6,668 KB
testcase_12 AC 78 ms
8,372 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 92 ms
6,948 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 82 ms
7,152 KB
testcase_18 AC 59 ms
6,060 KB
testcase_19 AC 67 ms
6,612 KB
testcase_20 AC 128 ms
8,708 KB
testcase_21 AC 60 ms
5,988 KB
testcase_22 AC 27 ms
4,444 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 22 ms
4,380 KB
testcase_26 AC 111 ms
7,908 KB
testcase_27 AC 103 ms
7,584 KB
testcase_28 AC 72 ms
6,648 KB
testcase_29 AC 17 ms
4,376 KB
testcase_30 AC 93 ms
7,064 KB
testcase_31 AC 80 ms
6,528 KB
testcase_32 AC 34 ms
4,904 KB
testcase_33 AC 90 ms
7,540 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 17 ms
4,376 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 40 ms
4,920 KB
testcase_38 AC 6 ms
4,652 KB
testcase_39 AC 42 ms
4,940 KB
testcase_40 AC 11 ms
4,376 KB
testcase_41 AC 5 ms
4,404 KB
testcase_42 AC 89 ms
7,072 KB
testcase_43 AC 21 ms
5,948 KB
testcase_44 AC 59 ms
5,928 KB
testcase_45 AC 7 ms
4,376 KB
testcase_46 AC 20 ms
5,992 KB
testcase_47 AC 56 ms
6,216 KB
testcase_48 AC 64 ms
6,580 KB
testcase_49 AC 17 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 18 ms
4,380 KB
testcase_52 AC 36 ms
6,132 KB
testcase_53 AC 11 ms
4,380 KB
testcase_54 AC 10 ms
4,384 KB
testcase_55 AC 36 ms
7,684 KB
testcase_56 AC 47 ms
8,608 KB
testcase_57 AC 50 ms
8,868 KB
testcase_58 AC 26 ms
6,328 KB
testcase_59 AC 55 ms
9,744 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

pair<int, int> solve(int s, int N, const vector<vector<int>> & edges){
    vector<int> dist(N, -1);
    int f = 0;
    int d = 0;
    dist[s] = d;
    vector<int> pool = {s};
    vector<int> next_pool;
    while (pool.size()){
        next_pool.clear();
        ++d;
        for (auto p: pool){
            for (auto q: edges[p]){
                if (dist[q] == -1){
                    dist[q] = d;
                    next_pool.push_back(q);
                    ++f;
                }
            }
        }
        swap(pool, next_pool);
    }
    d = *max_element(dist.begin(), dist.end());
    int days = 0;
    int tmp = 1;
    while (d > tmp){
        ++days;
        tmp *= 2;
    }
    return make_pair(f, days);
}

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edges(N);
    while (M--){
        int p, q;
        cin >> p >> q;
        edges[p - 1].push_back(q - 1);
        edges[q - 1].push_back(p - 1);
    }
    int Q;
    cin >> Q;
    while (Q--){
        int A;
        cin >> A;
        auto ans = solve(A - 1, N, edges);
        cout << ans.first << ' ' << ans.second << "\n";
    }
    return 0;
}
0