結果

問題 No.812 Change of Class
ユーザー merom686merom686
提出日時 2019-04-12 21:50:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 4,000 ms
コード長 1,529 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 78,852 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-09-03 01:21:09
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
5,220 KB
testcase_01 AC 7 ms
4,380 KB
testcase_02 AC 19 ms
4,532 KB
testcase_03 AC 39 ms
5,664 KB
testcase_04 AC 36 ms
5,424 KB
testcase_05 AC 116 ms
5,732 KB
testcase_06 AC 108 ms
5,428 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 99 ms
5,716 KB
testcase_10 AC 102 ms
5,652 KB
testcase_11 AC 6 ms
4,408 KB
testcase_12 AC 58 ms
5,388 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 70 ms
4,876 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 63 ms
4,904 KB
testcase_18 AC 46 ms
4,500 KB
testcase_19 AC 54 ms
4,824 KB
testcase_20 AC 107 ms
5,720 KB
testcase_21 AC 44 ms
4,444 KB
testcase_22 AC 20 ms
4,380 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 16 ms
4,380 KB
testcase_26 AC 86 ms
5,092 KB
testcase_27 AC 75 ms
4,980 KB
testcase_28 AC 51 ms
4,604 KB
testcase_29 AC 13 ms
4,380 KB
testcase_30 AC 67 ms
4,812 KB
testcase_31 AC 59 ms
4,592 KB
testcase_32 AC 25 ms
4,384 KB
testcase_33 AC 71 ms
5,104 KB
testcase_34 AC 6 ms
4,376 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 35 ms
4,380 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 35 ms
4,380 KB
testcase_40 AC 9 ms
4,384 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 75 ms
4,896 KB
testcase_43 AC 12 ms
4,400 KB
testcase_44 AC 52 ms
4,376 KB
testcase_45 AC 7 ms
4,384 KB
testcase_46 AC 11 ms
4,380 KB
testcase_47 AC 51 ms
4,496 KB
testcase_48 AC 49 ms
4,688 KB
testcase_49 AC 16 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 13 ms
4,380 KB
testcase_52 AC 24 ms
4,380 KB
testcase_53 AC 11 ms
4,384 KB
testcase_54 AC 9 ms
4,384 KB
testcase_55 AC 22 ms
4,988 KB
testcase_56 AC 25 ms
5,160 KB
testcase_57 AC 26 ms
5,204 KB
testcase_58 AC 15 ms
4,380 KB
testcase_59 AC 29 ms
5,724 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, d; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, -1 }), e(m), q(n), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void bfs(int i0) {
        for (int i = 0; i < n; i++) {
            v[i].d = -1;
        }
        v[i0].d = 0;
        int j0 = 0, j1 = 0;
        q[j1++] = i0;
        int c = 0, d = 0;
        while (j0 < j1) {
            int i = q[j0++];
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                if (v[o.i].d >= 0) continue;
                c++;
                d = max(d, v[o.i].d = v[i].d + 1);
                q[j1++] = o.i;
            }
        }
        int k = 0;
        while (1 << k < d) k++;
        cout << c << ' ' << k << endl;
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<int> q;
    int n, m;
};

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

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

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    int q;
    cin >> q;

    for (int h = 0; h < q; h++) {
        int a;
        cin >> a;
        a--;

        g.bfs(a);
    }

    return 0;
}
0