結果

問題 No.812 Change of Class
ユーザー peroonperoon
提出日時 2019-04-17 13:48:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 4,000 ms
コード長 1,563 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 175,484 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2023-09-03 15:10:43
合計ジャッジ時間 7,156 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
8,096 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 26 ms
5,776 KB
testcase_03 AC 55 ms
8,880 KB
testcase_04 AC 49 ms
8,340 KB
testcase_05 AC 168 ms
9,548 KB
testcase_06 AC 133 ms
8,688 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 162 ms
10,128 KB
testcase_10 AC 154 ms
10,124 KB
testcase_11 AC 14 ms
7,016 KB
testcase_12 AC 95 ms
9,056 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 93 ms
7,724 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 88 ms
8,120 KB
testcase_18 AC 64 ms
6,940 KB
testcase_19 AC 74 ms
6,952 KB
testcase_20 AC 155 ms
9,708 KB
testcase_21 AC 62 ms
6,896 KB
testcase_22 AC 28 ms
4,808 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 22 ms
4,564 KB
testcase_26 AC 117 ms
8,644 KB
testcase_27 AC 102 ms
7,740 KB
testcase_28 AC 70 ms
7,332 KB
testcase_29 AC 17 ms
4,380 KB
testcase_30 AC 91 ms
7,480 KB
testcase_31 AC 78 ms
7,284 KB
testcase_32 AC 35 ms
5,280 KB
testcase_33 AC 98 ms
8,664 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 18 ms
4,508 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 43 ms
5,496 KB
testcase_38 AC 6 ms
4,656 KB
testcase_39 AC 44 ms
5,424 KB
testcase_40 AC 12 ms
4,392 KB
testcase_41 AC 5 ms
4,392 KB
testcase_42 AC 93 ms
7,464 KB
testcase_43 AC 21 ms
6,236 KB
testcase_44 AC 63 ms
6,308 KB
testcase_45 AC 8 ms
4,380 KB
testcase_46 AC 19 ms
6,140 KB
testcase_47 AC 62 ms
6,196 KB
testcase_48 AC 70 ms
7,052 KB
testcase_49 AC 18 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 19 ms
4,764 KB
testcase_52 AC 38 ms
6,528 KB
testcase_53 AC 12 ms
4,376 KB
testcase_54 AC 10 ms
4,376 KB
testcase_55 AC 40 ms
8,252 KB
testcase_56 AC 40 ms
9,264 KB
testcase_57 AC 42 ms
9,272 KB
testcase_58 AC 23 ms
6,588 KB
testcase_59 AC 48 ms
10,272 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

vector<vector<ll> > G;
vector<ll> d;

pair<ll, ll> bfs(ll i){
    fill(ALL(d), -1);

    d[i] = 0;
    queue<ll> que;
    que.push(i);

    pair<ll, ll> answer;
    ll friend_num = 0;
    ll longest_distance = 0;

    while(!que.empty()){
        ll a = que.front();
        que.pop();

        for(ll to : G[a]){
            if(d[to]==-1){
                d[to] = d[a]+1;
                que.push(to);
                friend_num++;
            }
        }
    }
    
    longest_distance = *max_element(ALL(d));

    if(friend_num==0){
        answer.first = 0;
        answer.second = 0;
    }
    else{
        ll days = ceil(log2(longest_distance));
        answer.first = friend_num;
        answer.second = days;
    }
    return answer;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N, M;
    cin >> N >> M;

    G.resize(N+1);
    d.resize(N+1);

    FOR(i, 0, M){
        ll p, q;
        cin >> p >> q;
        G[p].push_back(q);
        G[q].push_back(p);
    }

    ll Q;
    cin >> Q;

    FOR(i, 0, Q){
        ll a;
        cin >> a;

        auto p = bfs(a);
        p2(p.first, p.second);
    }
    
    return 0;
}
0