結果

問題 No.812 Change of Class
ユーザー hamuhei4869hamuhei4869
提出日時 2019-03-21 15:11:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 933 ms / 4,000 ms
コード長 1,787 bytes
コンパイル時間 4,291 ms
コンパイル使用メモリ 158,236 KB
実行使用メモリ 17,984 KB
最終ジャッジ日時 2023-09-03 01:08:57
合計ジャッジ時間 23,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
14,392 KB
testcase_01 AC 43 ms
5,044 KB
testcase_02 AC 154 ms
9,320 KB
testcase_03 AC 333 ms
16,516 KB
testcase_04 AC 299 ms
14,620 KB
testcase_05 AC 800 ms
17,616 KB
testcase_06 AC 731 ms
16,884 KB
testcase_07 AC 8 ms
4,524 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 923 ms
17,924 KB
testcase_10 AC 933 ms
17,864 KB
testcase_11 AC 100 ms
8,092 KB
testcase_12 AC 651 ms
15,368 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 487 ms
12,752 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 475 ms
14,328 KB
testcase_18 AC 323 ms
10,692 KB
testcase_19 AC 382 ms
11,976 KB
testcase_20 AC 803 ms
17,380 KB
testcase_21 AC 306 ms
10,504 KB
testcase_22 AC 131 ms
6,564 KB
testcase_23 AC 23 ms
4,380 KB
testcase_24 AC 36 ms
4,376 KB
testcase_25 AC 105 ms
6,144 KB
testcase_26 AC 621 ms
16,584 KB
testcase_27 AC 542 ms
13,764 KB
testcase_28 AC 383 ms
12,040 KB
testcase_29 AC 74 ms
5,152 KB
testcase_30 AC 471 ms
13,356 KB
testcase_31 AC 383 ms
11,504 KB
testcase_32 AC 171 ms
7,352 KB
testcase_33 AC 565 ms
14,880 KB
testcase_34 AC 34 ms
4,376 KB
testcase_35 AC 89 ms
5,704 KB
testcase_36 AC 32 ms
4,380 KB
testcase_37 AC 201 ms
7,816 KB
testcase_38 AC 29 ms
5,116 KB
testcase_39 AC 205 ms
7,912 KB
testcase_40 AC 55 ms
4,924 KB
testcase_41 AC 20 ms
4,848 KB
testcase_42 AC 477 ms
12,548 KB
testcase_43 AC 195 ms
8,756 KB
testcase_44 AC 302 ms
9,852 KB
testcase_45 AC 32 ms
4,384 KB
testcase_46 AC 185 ms
8,924 KB
testcase_47 AC 306 ms
9,900 KB
testcase_48 AC 386 ms
11,120 KB
testcase_49 AC 80 ms
5,544 KB
testcase_50 AC 5 ms
4,376 KB
testcase_51 AC 107 ms
6,112 KB
testcase_52 AC 268 ms
9,788 KB
testcase_53 AC 54 ms
4,748 KB
testcase_54 AC 46 ms
4,616 KB
testcase_55 AC 266 ms
13,404 KB
testcase_56 AC 320 ms
15,384 KB
testcase_57 AC 345 ms
17,096 KB
testcase_58 AC 167 ms
9,864 KB
testcase_59 AC 384 ms
17,984 KB
testcase_60 AC 1 ms
4,380 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;
const LL LINF = 1e18;

class Edge{
public:
    int from,to;
    LL cost;
    Edge(int f, int t,LL c){
        from = f;
        to = t;
        cost = c;
    }
};



std::vector<LL> dijkstra(int s,int N,vector<Edge> E){
    std::vector<LL> ans(N,LINF);
    std::vector<std::vector<Edge>> Edges(N);
    for(auto e : E){
        Edges.at(e.from).push_back(e);
    }
    queue<pair<LL,int>> que;
    ans.at(s)= 0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        pair<LL,int> p = que.front();que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(Edges.at(p.second).at(i).to) != LINF)continue;
                if(ans.at(p.second) + Edges.at(p.second).at(i).cost < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).cost;
                que.push(make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}
int main(){
    int N,M;
    cin >> N >> M;
    vector<Edge> Edges;
    for(int i = 0;i < M;i++){
        int p,q;cin >> p >> q;
        p--,q--;
        Edges.push_back(Edge(p,q,1));
        Edges.push_back(Edge(q,p,1));
    }
    int Q;cin >> Q;
    for(int i = 0;i < Q;i++){
        int A;cin >> A;
        A--;
        vector<LL> dis = dijkstra(A, N, Edges);

        LL d = 0;
        LL cnt = 0;
        for(int j = 0;j < N;j++){
            if(dis.at(j) != LINF){
                d = max(d, dis.at(j));
                cnt++;
            }
        }
        int ans = 0;
        if(d != 0)ans = ceil(log2(d));
        cout<<cnt-1<<" "<<ans<<endl;
    }
}
0