結果

問題 No.812 Change of Class
ユーザー Y17Y17
提出日時 2019-04-12 23:08:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 151,196 KB
実行使用メモリ 9,720 KB
最終ジャッジ日時 2023-09-03 14:05:58
合計ジャッジ時間 8,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
8,536 KB
testcase_01 AC 17 ms
6,376 KB
testcase_02 AC 49 ms
7,488 KB
testcase_03 AC 104 ms
9,000 KB
testcase_04 AC 92 ms
8,616 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 5 ms
6,112 KB
testcase_08 AC 5 ms
6,080 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 19 ms
6,912 KB
testcase_12 WA -
testcase_13 AC 5 ms
6,256 KB
testcase_14 AC 5 ms
5,996 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 27 ms
6,596 KB
testcase_36 AC 13 ms
6,196 KB
testcase_37 AC 59 ms
7,044 KB
testcase_38 AC 8 ms
6,360 KB
testcase_39 AC 62 ms
7,036 KB
testcase_40 AC 18 ms
6,384 KB
testcase_41 AC 7 ms
6,324 KB
testcase_42 AC 123 ms
8,076 KB
testcase_43 AC 34 ms
7,392 KB
testcase_44 AC 86 ms
7,604 KB
testcase_45 AC 13 ms
6,272 KB
testcase_46 AC 34 ms
7,296 KB
testcase_47 AC 90 ms
7,480 KB
testcase_48 AC 97 ms
7,868 KB
testcase_49 AC 27 ms
6,592 KB
testcase_50 AC 5 ms
6,116 KB
testcase_51 AC 29 ms
6,748 KB
testcase_52 AC 56 ms
7,728 KB
testcase_53 AC 19 ms
6,324 KB
testcase_54 AC 17 ms
6,444 KB
testcase_55 AC 69 ms
8,536 KB
testcase_56 AC 82 ms
9,124 KB
testcase_57 AC 88 ms
9,348 KB
testcase_58 AC 47 ms
7,632 KB
testcase_59 AC 99 ms
9,720 KB
testcase_60 AC 4 ms
6,252 KB
testcase_61 AC 4 ms
6,052 KB
testcase_62 AC 4 ms
6,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> graph[100010];

int 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(cost != 0) cnt++;

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

            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