結果

問題 No.812 Change of Class
ユーザー algon_320algon_320
提出日時 2019-04-12 22:29:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 4,000 ms
コード長 1,400 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 173,488 KB
実行使用メモリ 10,344 KB
最終ジャッジ日時 2023-09-03 13:21:41
合計ジャッジ時間 8,226 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
8,208 KB
testcase_01 AC 13 ms
4,376 KB
testcase_02 AC 42 ms
5,896 KB
testcase_03 AC 89 ms
8,792 KB
testcase_04 AC 78 ms
8,356 KB
testcase_05 AC 217 ms
9,176 KB
testcase_06 AC 176 ms
8,428 KB
testcase_07 AC 3 ms
4,408 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 211 ms
9,620 KB
testcase_10 AC 207 ms
9,736 KB
testcase_11 AC 17 ms
7,016 KB
testcase_12 AC 129 ms
9,212 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 124 ms
7,288 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 117 ms
7,948 KB
testcase_18 AC 87 ms
6,456 KB
testcase_19 AC 100 ms
6,944 KB
testcase_20 AC 216 ms
9,560 KB
testcase_21 AC 84 ms
6,388 KB
testcase_22 AC 37 ms
4,656 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 11 ms
4,380 KB
testcase_25 AC 30 ms
4,380 KB
testcase_26 AC 164 ms
8,748 KB
testcase_27 AC 140 ms
7,932 KB
testcase_28 AC 99 ms
6,976 KB
testcase_29 AC 21 ms
4,380 KB
testcase_30 AC 124 ms
7,692 KB
testcase_31 AC 104 ms
6,732 KB
testcase_32 AC 47 ms
5,100 KB
testcase_33 AC 134 ms
8,376 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 24 ms
4,380 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 57 ms
5,188 KB
testcase_38 AC 7 ms
4,688 KB
testcase_39 AC 60 ms
5,188 KB
testcase_40 AC 15 ms
4,376 KB
testcase_41 AC 5 ms
4,440 KB
testcase_42 AC 128 ms
7,244 KB
testcase_43 AC 33 ms
6,308 KB
testcase_44 AC 86 ms
6,152 KB
testcase_45 AC 10 ms
4,380 KB
testcase_46 AC 31 ms
6,292 KB
testcase_47 AC 86 ms
6,204 KB
testcase_48 AC 102 ms
6,996 KB
testcase_49 AC 24 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 27 ms
4,564 KB
testcase_52 AC 57 ms
6,504 KB
testcase_53 AC 16 ms
4,376 KB
testcase_54 AC 13 ms
4,376 KB
testcase_55 AC 66 ms
8,112 KB
testcase_56 AC 78 ms
9,160 KB
testcase_57 AC 82 ms
9,588 KB
testcase_58 AC 44 ms
6,584 KB
testcase_59 AC 94 ms
10,344 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
template <class T>
bool chmax(T &a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr int INF = 1e9;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int Q;
    cin >> Q;
    rep(i, 0, Q) {
        int A;
        cin >> A;
        A--;

        vector<int> dist(N, INF);
        queue<int> q;
        q.push(A);
        dist[A] = 0;
        int sum = 0;
        int mx = 0;
        while (q.size()) {
            int v = q.front(); q.pop();
            for (int w : g[v]) {
                if (dist[w] > dist[v] + 1) {
                    dist[w] = dist[v] + 1;
                    chmax(mx, dist[w]);
                    q.push(w);
                    sum++;
                }
            }
        }

        int cnt = 0;
        if (mx > 0) {
            mx--;
            while (mx) {
                mx >>= 1;
                cnt++;
            }
        }
        cout << sum << " " << cnt << endl;
    }
}
0