結果

問題 No.812 Change of Class
ユーザー commycommy
提出日時 2020-04-10 00:31:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 4,000 ms
コード長 2,495 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 91,812 KB
実行使用メモリ 9,648 KB
最終ジャッジ日時 2023-10-12 03:44:26
合計ジャッジ時間 11,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
7,816 KB
testcase_01 AC 11 ms
4,352 KB
testcase_02 AC 36 ms
5,632 KB
testcase_03 AC 76 ms
8,640 KB
testcase_04 AC 67 ms
8,112 KB
testcase_05 AC 250 ms
8,284 KB
testcase_06 AC 215 ms
7,032 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 223 ms
8,800 KB
testcase_10 AC 230 ms
8,976 KB
testcase_11 AC 12 ms
6,660 KB
testcase_12 AC 111 ms
8,404 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 132 ms
6,700 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 125 ms
7,244 KB
testcase_18 AC 90 ms
5,896 KB
testcase_19 AC 103 ms
6,408 KB
testcase_20 AC 229 ms
8,752 KB
testcase_21 AC 81 ms
5,944 KB
testcase_22 AC 36 ms
4,348 KB
testcase_23 AC 7 ms
4,352 KB
testcase_24 AC 10 ms
4,352 KB
testcase_25 AC 29 ms
4,352 KB
testcase_26 AC 170 ms
7,940 KB
testcase_27 AC 142 ms
7,248 KB
testcase_28 AC 102 ms
6,432 KB
testcase_29 AC 21 ms
4,352 KB
testcase_30 AC 128 ms
7,216 KB
testcase_31 AC 107 ms
6,360 KB
testcase_32 AC 46 ms
4,640 KB
testcase_33 AC 147 ms
7,628 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 22 ms
4,348 KB
testcase_36 AC 9 ms
4,352 KB
testcase_37 AC 57 ms
4,940 KB
testcase_38 AC 6 ms
4,644 KB
testcase_39 AC 60 ms
5,040 KB
testcase_40 AC 14 ms
4,348 KB
testcase_41 AC 6 ms
4,352 KB
testcase_42 AC 122 ms
7,164 KB
testcase_43 AC 22 ms
5,964 KB
testcase_44 AC 86 ms
5,708 KB
testcase_45 AC 10 ms
4,348 KB
testcase_46 AC 22 ms
5,980 KB
testcase_47 AC 86 ms
5,948 KB
testcase_48 AC 92 ms
6,560 KB
testcase_49 AC 23 ms
4,352 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 23 ms
4,480 KB
testcase_52 AC 47 ms
6,160 KB
testcase_53 AC 16 ms
4,348 KB
testcase_54 AC 13 ms
4,348 KB
testcase_55 AC 57 ms
7,732 KB
testcase_56 AC 66 ms
8,700 KB
testcase_57 AC 71 ms
9,080 KB
testcase_58 AC 37 ms
6,084 KB
testcase_59 AC 81 ms
9,648 KB
testcase_60 AC 2 ms
4,352 KB
testcase_61 AC 2 ms
4,352 KB
testcase_62 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <queue>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    vector<vector<int>> G(n);
    REP(i, 0, m) {
        int a, b;
        cin, a, b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    auto bfs = [&](int root) -> P {
        vector<bool> used(n, false);
        vector<int> cost(n, -1);
        queue<P> q;  // cost, vertex
        q.emplace(0, root);
        while (q.size()) {
            auto [c, v] = q.front();
            q.pop();
            if (used[v]) continue;
            used[v] = true;
            cost[v] = c;
            for (auto nxt : G[v]) {
                if (used[nxt]) continue;
                q.emplace(c + 1, nxt);
            }
        }
        int res = -1, day = 0;
        REP(i, 0, n) {
            res += used[i];
            chmax(day, cost[i]);
        }
        dump(day);
        int ans = 0;
        while (day > 1) {
            ans++;
            day = (day + 1) / 2;
        }
        return P(res, ans);
    };
    int q;
    cin, q;
    REP(i, 0, q) {
        int a;
        cin, a;
        auto res = bfs(a - 1);
        print(res.first, res.second);
    }

    return 0;
}
0