結果

問題 No.812 Change of Class
ユーザー treeonetreeone
提出日時 2019-04-12 21:56:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 4,000 ms
コード長 1,361 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 205,064 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-09-03 01:29:47
合計ジャッジ時間 7,917 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
8,960 KB
testcase_01 AC 11 ms
6,240 KB
testcase_02 AC 27 ms
7,416 KB
testcase_03 AC 55 ms
9,448 KB
testcase_04 AC 48 ms
8,924 KB
testcase_05 AC 171 ms
9,888 KB
testcase_06 AC 132 ms
9,516 KB
testcase_07 AC 6 ms
6,004 KB
testcase_08 AC 4 ms
5,836 KB
testcase_09 AC 153 ms
10,040 KB
testcase_10 AC 165 ms
10,024 KB
testcase_11 AC 15 ms
7,268 KB
testcase_12 AC 103 ms
9,420 KB
testcase_13 AC 4 ms
5,728 KB
testcase_14 AC 4 ms
5,804 KB
testcase_15 AC 100 ms
8,548 KB
testcase_16 AC 9 ms
5,988 KB
testcase_17 AC 92 ms
8,736 KB
testcase_18 AC 69 ms
7,928 KB
testcase_19 AC 78 ms
8,288 KB
testcase_20 AC 160 ms
10,144 KB
testcase_21 AC 65 ms
8,092 KB
testcase_22 AC 31 ms
6,724 KB
testcase_23 AC 8 ms
5,944 KB
testcase_24 AC 11 ms
6,072 KB
testcase_25 AC 25 ms
6,512 KB
testcase_26 AC 122 ms
9,272 KB
testcase_27 AC 107 ms
9,080 KB
testcase_28 AC 74 ms
8,392 KB
testcase_29 AC 20 ms
6,268 KB
testcase_30 AC 95 ms
8,664 KB
testcase_31 AC 83 ms
8,196 KB
testcase_32 AC 37 ms
6,976 KB
testcase_33 AC 104 ms
9,080 KB
testcase_34 AC 10 ms
6,000 KB
testcase_35 AC 21 ms
6,432 KB
testcase_36 AC 9 ms
6,044 KB
testcase_37 AC 44 ms
7,172 KB
testcase_38 AC 7 ms
6,324 KB
testcase_39 AC 46 ms
7,176 KB
testcase_40 AC 14 ms
6,168 KB
testcase_41 AC 6 ms
6,168 KB
testcase_42 AC 99 ms
8,536 KB
testcase_43 AC 24 ms
7,564 KB
testcase_44 AC 66 ms
7,816 KB
testcase_45 AC 10 ms
5,992 KB
testcase_46 AC 22 ms
7,548 KB
testcase_47 AC 65 ms
7,764 KB
testcase_48 AC 74 ms
8,200 KB
testcase_49 AC 20 ms
6,560 KB
testcase_50 AC 4 ms
5,748 KB
testcase_51 AC 23 ms
6,624 KB
testcase_52 AC 45 ms
7,780 KB
testcase_53 AC 14 ms
6,252 KB
testcase_54 AC 12 ms
6,264 KB
testcase_55 AC 42 ms
8,952 KB
testcase_56 AC 41 ms
9,804 KB
testcase_57 AC 44 ms
9,868 KB
testcase_58 AC 24 ms
7,732 KB
testcase_59 AC 49 ms
10,400 KB
testcase_60 AC 4 ms
5,720 KB
testcase_61 AC 4 ms
5,984 KB
testcase_62 AC 3 ms
5,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m;
vector<int> G[100010];
int d[100010];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, 0, m){
        int p, q;
        cin >> p >> q;
        p--; q--;
        G[p].push_back(q);
        G[q].push_back(p);
    }
    int Q;
    cin >> Q;
    while(Q--){
        int a;
        cin >> a;
        a--;
        rep(i, 0, n) d[i] = -1;
        queue<int> q;
        q.push(a);
        d[a] = 0;
        while(!q.empty()){
            int tmp = q.front(); q.pop();
            for(auto i : G[tmp]){
                if(d[i] != -1) continue;
                d[i] = d[tmp] + 1;
                q.push(i);
            }
        }
        int ans = 0, day = 0;
        rep(i, 0, n){
            if(d[i] != -1){
                ans++;
                day = max(day, d[i]);
            }
        }
        if(ans == 0) cout << 0 << ' ' << 0 << endl;
        else{
            int now = 1;
            for(int j = 0;; j++){
                if(day <= now){
                    day = j; break;
                }
                now *= 2;
            }
            cout << ans - 1 << ' ' <<  day << endl;
        }
    }
}
0