結果

問題 No.812 Change of Class
ユーザー Y17Y17
提出日時 2019-04-12 23:13:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 246 ms / 4,000 ms
コード長 1,261 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 152,476 KB
実行使用メモリ 11,332 KB
最終ジャッジ日時 2023-09-03 14:09:24
合計ジャッジ時間 9,067 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
9,120 KB
testcase_01 AC 17 ms
6,892 KB
testcase_02 AC 45 ms
7,988 KB
testcase_03 AC 94 ms
9,444 KB
testcase_04 AC 83 ms
9,148 KB
testcase_05 AC 246 ms
10,220 KB
testcase_06 AC 243 ms
10,292 KB
testcase_07 AC 6 ms
6,700 KB
testcase_08 AC 6 ms
6,628 KB
testcase_09 AC 228 ms
10,220 KB
testcase_10 AC 230 ms
10,212 KB
testcase_11 AC 18 ms
7,252 KB
testcase_12 AC 133 ms
9,488 KB
testcase_13 AC 5 ms
6,472 KB
testcase_14 AC 5 ms
6,508 KB
testcase_15 AC 146 ms
9,000 KB
testcase_16 AC 13 ms
6,828 KB
testcase_17 AC 136 ms
9,292 KB
testcase_18 AC 100 ms
8,444 KB
testcase_19 AC 116 ms
8,980 KB
testcase_20 AC 224 ms
10,128 KB
testcase_21 AC 99 ms
8,340 KB
testcase_22 AC 45 ms
7,344 KB
testcase_23 AC 11 ms
6,664 KB
testcase_24 AC 16 ms
6,760 KB
testcase_25 AC 37 ms
7,156 KB
testcase_26 AC 188 ms
9,540 KB
testcase_27 AC 165 ms
9,148 KB
testcase_28 AC 113 ms
8,728 KB
testcase_29 AC 28 ms
6,952 KB
testcase_30 AC 148 ms
9,072 KB
testcase_31 AC 121 ms
8,636 KB
testcase_32 AC 56 ms
7,744 KB
testcase_33 AC 147 ms
9,524 KB
testcase_34 AC 14 ms
6,800 KB
testcase_35 AC 28 ms
7,088 KB
testcase_36 AC 14 ms
6,740 KB
testcase_37 AC 64 ms
7,780 KB
testcase_38 AC 9 ms
6,704 KB
testcase_39 AC 66 ms
7,672 KB
testcase_40 AC 19 ms
6,880 KB
testcase_41 AC 8 ms
6,644 KB
testcase_42 AC 140 ms
8,948 KB
testcase_43 AC 36 ms
8,020 KB
testcase_44 AC 95 ms
8,164 KB
testcase_45 AC 14 ms
6,872 KB
testcase_46 AC 34 ms
7,800 KB
testcase_47 AC 94 ms
8,216 KB
testcase_48 AC 103 ms
8,488 KB
testcase_49 AC 30 ms
7,108 KB
testcase_50 AC 6 ms
6,496 KB
testcase_51 AC 31 ms
7,240 KB
testcase_52 AC 59 ms
8,160 KB
testcase_53 AC 21 ms
6,892 KB
testcase_54 AC 18 ms
6,968 KB
testcase_55 AC 77 ms
9,736 KB
testcase_56 AC 91 ms
10,440 KB
testcase_57 AC 97 ms
10,736 KB
testcase_58 AC 51 ms
8,632 KB
testcase_59 AC 112 ms
11,332 KB
testcase_60 AC 4 ms
6,564 KB
testcase_61 AC 4 ms
6,468 KB
testcase_62 AC 4 ms
6,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

vector<int> graph[100010];

signed main(){
    int n, m;
    cin >> n >> m;

    int a, b;
    for(int i = 0;i < m;i++){
        cin >> a >> b;
        a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int q;
    cin >> q;

    for(int p = 0;p < q;p++){
        int dist[100010];
        memset(dist, -1, sizeof(dist));

        int fi;
        cin >> fi;
        queue<pair<int, int>> que;
        fi--;
        que.push(make_pair(fi, 0));

        int cnt = 0;
        while(!que.empty()){
            int idx = que.front().first;
            int cost = que.front().second;
            que.pop();

            if(dist[idx] != -1) continue;
            dist[idx] = cost;
            if(cost != 0) cnt++;

            for(int i = 0;i < graph[idx].size();i++){
                if(dist[graph[idx][i]] == -1){
                    que.push(make_pair(graph[idx][i], cost+1));
                }
            }
        }

        int ma = -2;
        for(int i = 0;i < n;i++){
            ma = max(ma, dist[i]);
        }
        int ans;
        int i;
        for(i = 0,ans=1;ans < ma;i++,ans*=2);
        cout << cnt << " " << i << endl;
    }

    return 0;
}


0