結果

問題 No.812 Change of Class
コンテスト
ユーザー betrue12
提出日時 2019-04-12 21:53:28
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 120 ms / 4,000 ms
コード長 896 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,386 ms
コンパイル使用メモリ 190,320 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2026-03-05 12:32:20
合計ジャッジ時間 5,334 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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