結果

問題 No.812 Change of Class
ユーザー outlineoutline
提出日時 2020-12-18 22:33:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 4,000 ms
コード長 2,081 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 140,116 KB
実行使用メモリ 9,500 KB
最終ジャッジ日時 2023-10-21 08:26:25
合計ジャッジ時間 7,836 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
8,044 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 29 ms
5,856 KB
testcase_03 AC 61 ms
8,816 KB
testcase_04 AC 54 ms
8,200 KB
testcase_05 AC 155 ms
8,184 KB
testcase_06 AC 123 ms
7,176 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 157 ms
8,888 KB
testcase_10 AC 146 ms
8,888 KB
testcase_11 AC 16 ms
6,820 KB
testcase_12 AC 105 ms
8,544 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 99 ms
6,912 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 95 ms
7,320 KB
testcase_18 AC 69 ms
6,120 KB
testcase_19 AC 78 ms
6,648 KB
testcase_20 AC 156 ms
8,760 KB
testcase_21 AC 67 ms
5,968 KB
testcase_22 AC 30 ms
4,536 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 24 ms
4,348 KB
testcase_26 AC 123 ms
7,952 KB
testcase_27 AC 106 ms
7,416 KB
testcase_28 AC 74 ms
6,648 KB
testcase_29 AC 18 ms
4,348 KB
testcase_30 AC 96 ms
7,248 KB
testcase_31 AC 82 ms
6,384 KB
testcase_32 AC 37 ms
4,800 KB
testcase_33 AC 99 ms
7,696 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 19 ms
4,348 KB
testcase_36 AC 8 ms
4,348 KB
testcase_37 AC 47 ms
5,248 KB
testcase_38 AC 7 ms
4,800 KB
testcase_39 AC 48 ms
5,248 KB
testcase_40 AC 13 ms
4,348 KB
testcase_41 AC 6 ms
4,536 KB
testcase_42 AC 103 ms
7,176 KB
testcase_43 AC 23 ms
6,124 KB
testcase_44 AC 68 ms
5,992 KB
testcase_45 AC 9 ms
4,348 KB
testcase_46 AC 21 ms
6,120 KB
testcase_47 AC 68 ms
6,120 KB
testcase_48 AC 76 ms
6,652 KB
testcase_49 AC 19 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 23 ms
4,536 KB
testcase_52 AC 46 ms
6,384 KB
testcase_53 AC 14 ms
4,348 KB
testcase_54 AC 11 ms
4,348 KB
testcase_55 AC 44 ms
7,628 KB
testcase_56 AC 51 ms
8,492 KB
testcase_57 AC 54 ms
8,784 KB
testcase_58 AC 29 ms
6,084 KB
testcase_59 AC 61 ms
9,500 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N, M, Q, A;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < M; ++i){
        int p, q;
        cin >> p >> q;
        --p, --q;
        graph[p].emplace_back(q);
        graph[q].emplace_back(p);
    }
    vector<int> pow2(26, 1);
    for(int i = 1; i <= 25; ++i)    pow2[i] = pow2[i - 1] * 2;
    cin >> Q;
    for(int q = 0; q < Q; ++q){
        cin >> A;
        --A;
        vector<int> dist(N, INF);
        dist[A] = 0;
        queue<int> que;
        que.emplace(A);
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(int to : graph[from]){
                if(chmin(dist[to], dist[from] + 1)){
                    que.emplace(to);
                }
            }
        }
        int cnt = 0, max_dist = 0;
        for(int i = 0; i < N; ++i){
            if(i == A || dist[i] == INF)    continue;
            cnt += 1;
            chmax(max_dist, dist[i]);
        }
        int day = lower_bound(begin(pow2), end(pow2), max_dist) - begin(pow2);
        cout << cnt << ' ' << day << '\n';
    }
    
    return 0;
}
0