結果

問題 No.812 Change of Class
ユーザー betrue12betrue12
提出日時 2019-04-12 21:53:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 203 ms / 4,000 ms
コード長 896 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 174,588 KB
実行使用メモリ 9,592 KB
最終ジャッジ日時 2024-06-12 07:00:52
合計ジャッジ時間 8,105 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> edges[100000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    int Q;
    cin >> Q;
    while(Q--){
        int a;
        cin >> a;
        a--;
        const int INF = 1e9;
        vector<int> dist(N, INF);
        dist[a] = 0;
        queue<int> que;
        que.push(a);
        int num = -1, mx = 0;
        while(que.size()){
            int i = que.front(); que.pop();
            num++;
            mx = dist[i];
            for(int j : edges[i]) if(dist[j] == INF){
                dist[j] = dist[i] + 1;
                que.push(j);
            }
        }
        int day = 0;
        while((1<<day) < mx) day++;
        cout << num << " " << day << endl;
    }
    return 0;
}
0