結果

問題 No.812 Change of Class
ユーザー chocoruskchocorusk
提出日時 2019-04-12 21:46:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 183 ms / 4,000 ms
コード長 1,407 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 100,816 KB
実行使用メモリ 9,412 KB
最終ジャッジ日時 2023-09-03 01:11:20
合計ジャッジ時間 7,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
8,484 KB
testcase_01 AC 13 ms
6,108 KB
testcase_02 AC 41 ms
7,264 KB
testcase_03 AC 87 ms
8,992 KB
testcase_04 AC 78 ms
8,724 KB
testcase_05 AC 183 ms
8,584 KB
testcase_06 AC 162 ms
8,132 KB
testcase_07 AC 5 ms
5,836 KB
testcase_08 AC 4 ms
5,764 KB
testcase_09 AC 172 ms
8,928 KB
testcase_10 AC 178 ms
9,088 KB
testcase_11 AC 20 ms
6,880 KB
testcase_12 AC 123 ms
8,580 KB
testcase_13 AC 3 ms
5,696 KB
testcase_14 AC 4 ms
5,660 KB
testcase_15 AC 116 ms
7,792 KB
testcase_16 AC 10 ms
6,012 KB
testcase_17 AC 113 ms
7,936 KB
testcase_18 AC 84 ms
7,348 KB
testcase_19 AC 96 ms
7,628 KB
testcase_20 AC 176 ms
8,832 KB
testcase_21 AC 80 ms
7,412 KB
testcase_22 AC 37 ms
6,508 KB
testcase_23 AC 9 ms
5,836 KB
testcase_24 AC 12 ms
5,928 KB
testcase_25 AC 30 ms
6,328 KB
testcase_26 AC 145 ms
8,352 KB
testcase_27 AC 126 ms
8,016 KB
testcase_28 AC 93 ms
7,764 KB
testcase_29 AC 23 ms
6,268 KB
testcase_30 AC 119 ms
8,040 KB
testcase_31 AC 99 ms
7,596 KB
testcase_32 AC 46 ms
6,676 KB
testcase_33 AC 125 ms
8,344 KB
testcase_34 AC 11 ms
5,844 KB
testcase_35 AC 25 ms
6,280 KB
testcase_36 AC 11 ms
5,992 KB
testcase_37 AC 55 ms
6,920 KB
testcase_38 AC 9 ms
6,236 KB
testcase_39 AC 58 ms
6,836 KB
testcase_40 AC 18 ms
6,020 KB
testcase_41 AC 7 ms
5,988 KB
testcase_42 AC 119 ms
7,956 KB
testcase_43 AC 36 ms
7,264 KB
testcase_44 AC 79 ms
7,344 KB
testcase_45 AC 11 ms
5,984 KB
testcase_46 AC 33 ms
7,148 KB
testcase_47 AC 78 ms
7,496 KB
testcase_48 AC 92 ms
7,708 KB
testcase_49 AC 24 ms
6,300 KB
testcase_50 AC 4 ms
5,700 KB
testcase_51 AC 29 ms
6,424 KB
testcase_52 AC 59 ms
7,368 KB
testcase_53 AC 17 ms
6,072 KB
testcase_54 AC 15 ms
5,992 KB
testcase_55 AC 53 ms
8,384 KB
testcase_56 AC 59 ms
8,852 KB
testcase_57 AC 63 ms
8,892 KB
testcase_58 AC 34 ms
7,388 KB
testcase_59 AC 71 ms
9,412 KB
testcase_60 AC 3 ms
5,652 KB
testcase_61 AC 3 ms
5,752 KB
testcase_62 AC 4 ms
5,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e8;
int n, m;
vector<int> g[100001];
void bfs(int s, int d[100001]){
    fill(d, d+n, INF);
    d[s]=0;
    queue<int> que; que.push(s);
    while(!que.empty()){
        int x=que.front(); que.pop();
        for(auto y:g[x]){
            if(d[y]>d[x]+1){
                d[y]=d[x]+1;
                que.push(y);
            }
        }
    }
}

int main()
{
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int a, b; cin>>a>>b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int q; cin>>q;
    for(int i=0; i<q; i++){
        int a; cin>>a; a--;
        int d[100001];
        bfs(a, d);
        int ct=0;
        int mx=1;
        for(int i=0; i<n; i++){
            if(d[i]<INF){
                ct++;
                mx=max(mx, d[i]);
            }
        }
        int ans=0;
        int p2=1;
        while(p2<mx){
            p2<<=1; ans++;
        }
        cout<<ct-1<<" "<<ans<<endl;
    }
    return 0;
}
0