結果

問題 No.812 Change of Class
ユーザー rogi52rogi52
提出日時 2022-10-16 17:34:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 4,000 ms
コード長 1,045 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 205,752 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-09-09 19:52:57
合計ジャッジ時間 7,278 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
8,088 KB
testcase_01 AC 8 ms
4,376 KB
testcase_02 AC 26 ms
5,872 KB
testcase_03 AC 55 ms
8,784 KB
testcase_04 AC 49 ms
8,228 KB
testcase_05 AC 130 ms
8,220 KB
testcase_06 AC 109 ms
7,040 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 121 ms
9,168 KB
testcase_10 AC 127 ms
8,804 KB
testcase_11 AC 14 ms
6,832 KB
testcase_12 AC 84 ms
8,292 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 86 ms
6,872 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 79 ms
7,208 KB
testcase_18 AC 61 ms
6,068 KB
testcase_19 AC 67 ms
6,512 KB
testcase_20 AC 128 ms
8,584 KB
testcase_21 AC 58 ms
5,888 KB
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 113 ms
7,852 KB
testcase_27 AC 93 ms
7,336 KB
testcase_28 AC 67 ms
6,468 KB
testcase_29 AC 16 ms
4,380 KB
testcase_30 AC 85 ms
7,216 KB
testcase_31 AC 73 ms
6,312 KB
testcase_32 AC 33 ms
4,624 KB
testcase_33 AC 90 ms
7,612 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 16 ms
4,376 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 39 ms
5,204 KB
testcase_38 AC 6 ms
4,568 KB
testcase_39 AC 40 ms
5,164 KB
testcase_40 AC 11 ms
4,380 KB
testcase_41 AC 5 ms
4,468 KB
testcase_42 AC 84 ms
6,896 KB
testcase_43 AC 22 ms
5,988 KB
testcase_44 AC 57 ms
5,984 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 20 ms
6,012 KB
testcase_47 AC 55 ms
5,968 KB
testcase_48 AC 65 ms
6,688 KB
testcase_49 AC 16 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 19 ms
4,380 KB
testcase_52 AC 39 ms
6,300 KB
testcase_53 AC 11 ms
4,376 KB
testcase_54 AC 10 ms
4,376 KB
testcase_55 AC 36 ms
7,504 KB
testcase_56 AC 42 ms
8,392 KB
testcase_57 AC 45 ms
8,584 KB
testcase_58 AC 23 ms
6,028 KB
testcase_59 AC 51 ms
9,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<int> bfs(vector<vector<int>> &graph, int s) {
    int INF = numeric_limits<int>::max();
    vector<int> dist(graph.size(), INF);
    queue<int> q;
    dist[s] = 0, q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v : graph[u]) if(dist[v] == INF)
            dist[v] = dist[u] + 1, q.push(v);
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(_,M) {
        int p,q; cin >> p >> q; p--; q--;
        G[p].push_back(q);
        G[q].push_back(p);
    }

    int Q; cin >> Q;
    rep(_,Q) {
        int a; cin >> a; a--;
        auto dist = bfs(G, a);
        int cnt = 0, ma = 0;
        rep(i,N) if(dist[i] < 2e9) {
            cnt++;
            ma = max(ma, dist[i]);
        }
        ma = (ma == 0 ? 0 : (int)ceil(log2(ma)));
        cout << cnt - 1 << " " << ma << "\n";
    }
}
0