結果

問題 No.812 Change of Class
ユーザー tottoripapertottoripaper
提出日時 2019-04-12 22:11:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 4,000 ms
コード長 1,480 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 174,388 KB
実行使用メモリ 10,032 KB
最終ジャッジ日時 2023-09-03 13:13:49
合計ジャッジ時間 5,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
8,556 KB
testcase_01 AC 10 ms
6,164 KB
testcase_02 AC 25 ms
7,248 KB
testcase_03 AC 48 ms
9,000 KB
testcase_04 AC 43 ms
8,660 KB
testcase_05 AC 123 ms
8,728 KB
testcase_06 AC 96 ms
8,256 KB
testcase_07 AC 4 ms
5,904 KB
testcase_08 AC 3 ms
5,816 KB
testcase_09 AC 106 ms
9,048 KB
testcase_10 AC 109 ms
9,032 KB
testcase_11 AC 10 ms
6,904 KB
testcase_12 AC 69 ms
8,740 KB
testcase_13 AC 3 ms
5,732 KB
testcase_14 AC 3 ms
5,744 KB
testcase_15 AC 76 ms
8,040 KB
testcase_16 AC 7 ms
5,896 KB
testcase_17 AC 69 ms
8,080 KB
testcase_18 AC 54 ms
7,460 KB
testcase_19 AC 60 ms
7,704 KB
testcase_20 AC 112 ms
9,020 KB
testcase_21 AC 50 ms
7,396 KB
testcase_22 AC 24 ms
6,768 KB
testcase_23 AC 7 ms
6,032 KB
testcase_24 AC 9 ms
6,024 KB
testcase_25 AC 20 ms
6,304 KB
testcase_26 AC 94 ms
8,460 KB
testcase_27 AC 83 ms
8,064 KB
testcase_28 AC 57 ms
7,816 KB
testcase_29 AC 15 ms
6,160 KB
testcase_30 AC 73 ms
7,960 KB
testcase_31 AC 64 ms
7,668 KB
testcase_32 AC 30 ms
6,736 KB
testcase_33 AC 79 ms
8,288 KB
testcase_34 AC 9 ms
6,212 KB
testcase_35 AC 16 ms
6,316 KB
testcase_36 AC 7 ms
5,944 KB
testcase_37 AC 35 ms
6,888 KB
testcase_38 AC 5 ms
6,372 KB
testcase_39 AC 36 ms
6,868 KB
testcase_40 AC 11 ms
6,112 KB
testcase_41 AC 5 ms
6,064 KB
testcase_42 AC 72 ms
8,196 KB
testcase_43 AC 16 ms
7,232 KB
testcase_44 AC 50 ms
7,340 KB
testcase_45 AC 8 ms
5,956 KB
testcase_46 AC 15 ms
7,168 KB
testcase_47 AC 50 ms
7,372 KB
testcase_48 AC 57 ms
7,676 KB
testcase_49 AC 15 ms
6,288 KB
testcase_50 AC 4 ms
5,868 KB
testcase_51 AC 18 ms
6,440 KB
testcase_52 AC 34 ms
7,396 KB
testcase_53 AC 12 ms
6,176 KB
testcase_54 AC 10 ms
6,084 KB
testcase_55 AC 29 ms
8,548 KB
testcase_56 AC 35 ms
9,192 KB
testcase_57 AC 37 ms
9,288 KB
testcase_58 AC 21 ms
7,564 KB
testcase_59 AC 40 ms
10,032 KB
testcase_60 AC 3 ms
5,796 KB
testcase_61 AC 2 ms
5,812 KB
testcase_62 AC 3 ms
5,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

const int INF = 1001001001;
int N, M;
std::vector<int> G[100100];
int Q, A;
int dist[100100];
std::queue<P> que;

void dijkstra(int s){
    std::fill(dist + 1, dist + 1 + N, INF);
    dist[s] = 0;
    que.emplace(0, s);

    until(que.empty()){
        int d, v;
        std::tie(d, v) = que.front();
        que.pop();

        if(d > dist[v]){
            continue;
        }

        for(int w : G[v]){
            int di = dist[v] + 1;
            if(di < dist[w]){
                dist[w] = di;
                que.emplace(di, w);
            }
        }
    }
}

int f(int n){
    if(n <= 1){
        return 0;
    }

    return 32 - __builtin_clz(n - 1);
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int p, q;
        std::cin >> p >> q;

        G[p].emplace_back(q);
        G[q].emplace_back(p);
    }

    std::cin >> Q;

    for(int i=0;i<Q;++i){
        std::cin >> A;

        dijkstra(A);

        int c = 0, d = 0;

        for(int j=1;j<=N;++j){
            if(j != A && dist[j] < INF){
                c += 1;
                d = std::max(d, f(dist[j]));
            }
        }

        std::cout << c << " " << d << std::endl;
    }
}
0