結果

問題 No.812 Change of Class
ユーザー granddaifukugranddaifuku
提出日時 2020-04-26 19:15:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,609 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 174,040 KB
実行使用メモリ 9,428 KB
最終ジャッジ日時 2024-04-28 22:10:14
合計ジャッジ時間 8,565 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
7,956 KB
testcase_01 AC 10 ms
5,376 KB
testcase_02 AC 33 ms
5,888 KB
testcase_03 AC 68 ms
8,928 KB
testcase_04 AC 62 ms
8,308 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 10 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 19 ms
5,376 KB
testcase_36 AC 8 ms
5,376 KB
testcase_37 AC 47 ms
5,376 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 48 ms
5,376 KB
testcase_40 AC 12 ms
5,376 KB
testcase_41 AC 4 ms
5,376 KB
testcase_42 AC 106 ms
7,356 KB
testcase_43 AC 19 ms
6,500 KB
testcase_44 AC 71 ms
6,104 KB
testcase_45 AC 8 ms
5,376 KB
testcase_46 AC 19 ms
6,272 KB
testcase_47 AC 69 ms
6,124 KB
testcase_48 AC 75 ms
6,764 KB
testcase_49 AC 20 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 20 ms
5,376 KB
testcase_52 AC 40 ms
6,512 KB
testcase_53 AC 14 ms
5,376 KB
testcase_54 AC 11 ms
5,376 KB
testcase_55 AC 39 ms
7,608 KB
testcase_56 AC 46 ms
8,348 KB
testcase_57 AC 48 ms
8,568 KB
testcase_58 AC 24 ms
6,016 KB
testcase_59 AC 55 ms
9,428 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int check(int x) {
    int cnt = 0;
    while (x > 0) {
        x /= 2;
        cnt++;
    }

    return cnt;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m;
    vector<int> g[n];
    rep (i, m) {
        int s, t;
        cin >> s >> t;
        g[s - 1].push_back(t - 1);
        g[t - 1].push_back(s - 1);
    }
    cin >> q;
    rep (i, q) {
        int a;
        cin >> a;
        a--;
        if (g[a].size() == 0) {
            cout << 0 << " " << 0 << endl;
            continue;
        }
        int cnt = 0;
        int day = 0;
        vector<int> checked(n, Inf);
        queue<int> q;
        rep (j, g[a].size()) {
            q.push(g[a][j]);
            checked[g[a][j]] = 0;
            cnt++;
        }
        checked[a] = 0;
        while (!q.empty()) {
            int next = q.front();
            q.pop();
            rep (j, g[next].size()) {
                if (checked[g[next][j]] < checked[next] + 1) continue;
                checked[g[next][j]] = checked[next] + 1;
                q.push(g[next][j]);
                cnt++;
            }
            int tmp = check(checked[next]);
            day = max(day, tmp);
        }
        cout << cnt << " " << day << endl;
    }
    
    return 0;
}
0