結果

問題 No.812 Change of Class
ユーザー veqccveqcc
提出日時 2019-04-12 22:36:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 564 ms / 4,000 ms
コード長 1,659 bytes
コンパイル時間 1,328 ms
コンパイル使用メモリ 113,080 KB
実行使用メモリ 10,732 KB
最終ジャッジ日時 2023-09-03 13:47:54
合計ジャッジ時間 15,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
8,584 KB
testcase_01 AC 14 ms
6,184 KB
testcase_02 AC 40 ms
7,224 KB
testcase_03 AC 83 ms
9,000 KB
testcase_04 AC 73 ms
8,696 KB
testcase_05 AC 509 ms
9,000 KB
testcase_06 AC 383 ms
8,348 KB
testcase_07 AC 8 ms
6,028 KB
testcase_08 AC 5 ms
5,748 KB
testcase_09 AC 463 ms
9,128 KB
testcase_10 AC 540 ms
9,152 KB
testcase_11 AC 20 ms
6,880 KB
testcase_12 AC 256 ms
8,752 KB
testcase_13 AC 3 ms
5,692 KB
testcase_14 AC 4 ms
5,704 KB
testcase_15 AC 289 ms
7,840 KB
testcase_16 AC 18 ms
5,892 KB
testcase_17 AC 291 ms
7,988 KB
testcase_18 AC 193 ms
7,460 KB
testcase_19 AC 240 ms
7,560 KB
testcase_20 AC 564 ms
9,140 KB
testcase_21 AC 184 ms
7,504 KB
testcase_22 AC 77 ms
6,504 KB
testcase_23 AC 16 ms
5,856 KB
testcase_24 AC 23 ms
6,004 KB
testcase_25 AC 61 ms
6,376 KB
testcase_26 AC 449 ms
8,304 KB
testcase_27 AC 380 ms
7,988 KB
testcase_28 AC 205 ms
7,644 KB
testcase_29 AC 47 ms
6,368 KB
testcase_30 AC 270 ms
7,944 KB
testcase_31 AC 232 ms
7,708 KB
testcase_32 AC 94 ms
6,756 KB
testcase_33 AC 291 ms
8,372 KB
testcase_34 AC 21 ms
5,944 KB
testcase_35 AC 48 ms
6,364 KB
testcase_36 AC 25 ms
6,120 KB
testcase_37 AC 135 ms
6,876 KB
testcase_38 AC 9 ms
6,212 KB
testcase_39 AC 142 ms
6,880 KB
testcase_40 AC 32 ms
6,072 KB
testcase_41 AC 9 ms
5,988 KB
testcase_42 AC 293 ms
8,032 KB
testcase_43 AC 30 ms
7,268 KB
testcase_44 AC 205 ms
7,384 KB
testcase_45 AC 26 ms
6,012 KB
testcase_46 AC 27 ms
7,256 KB
testcase_47 AC 202 ms
7,448 KB
testcase_48 AC 223 ms
7,692 KB
testcase_49 AC 63 ms
6,364 KB
testcase_50 AC 6 ms
5,808 KB
testcase_51 AC 49 ms
6,696 KB
testcase_52 AC 87 ms
7,368 KB
testcase_53 AC 41 ms
6,088 KB
testcase_54 AC 36 ms
6,088 KB
testcase_55 AC 209 ms
9,044 KB
testcase_56 AC 255 ms
10,000 KB
testcase_57 AC 272 ms
10,336 KB
testcase_58 AC 139 ms
7,932 KB
testcase_59 AC 311 ms
10,732 KB
testcase_60 AC 3 ms
5,700 KB
testcase_61 AC 3 ms
5,784 KB
testcase_62 AC 3 ms
5,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair <int, int> P;

vector <int> edges[100005];

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        edges[p].push_back(q);
        edges[q].push_back(p);
    }

    int Q;
    cin >> Q;

    for (int x = 0; x < Q; x++) {
        int a;
        cin >> a;
        a--;

        priority_queue <P, vector<P>, greater<P>> q;
        q.push(P(0, a));

        vector <bool> visited(n, false);
        visited[a] = true;

        vector <int> cost(n, 1e9);
        cost[a] = 0;

        while (q.size()) {
            P cur = q.top();
            q.pop();

            int now = cur.second;
            int c = cur.first;

            if (cost[now] < c) continue;
            for (int node : edges[now]) {
                visited[node] = true;
                if (cost[node] > c + 1) {
                    cost[node] = c + 1;
                    q.push(P(c+1, node));
                }
            }
        }

        int cnt = -1;
        for (bool v : visited) if (v) cnt++;

        int depth = 0;
        for (int c : cost) if (c < 1e9) depth = max(depth, c);

        int ret = 0;
        while ((1 << ret) < depth) {
            ret++;
        }

        cout << cnt << " " << ret << "\n";
    }

    return 0;
}
0