結果

問題 No.812 Change of Class
ユーザー granddaifukugranddaifuku
提出日時 2020-04-26 19:33:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 558 ms / 4,000 ms
コード長 1,843 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 179,020 KB
実行使用メモリ 11,212 KB
最終ジャッジ日時 2024-04-28 22:46:48
合計ジャッジ時間 15,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
8,212 KB
testcase_01 AC 15 ms
5,376 KB
testcase_02 AC 48 ms
5,888 KB
testcase_03 AC 107 ms
9,088 KB
testcase_04 AC 92 ms
8,448 KB
testcase_05 AC 558 ms
9,244 KB
testcase_06 AC 425 ms
8,564 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 484 ms
10,224 KB
testcase_10 AC 471 ms
9,984 KB
testcase_11 AC 18 ms
7,204 KB
testcase_12 AC 286 ms
9,284 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 322 ms
7,552 KB
testcase_16 AC 20 ms
5,376 KB
testcase_17 AC 291 ms
8,104 KB
testcase_18 AC 208 ms
6,656 KB
testcase_19 AC 237 ms
7,296 KB
testcase_20 AC 534 ms
9,692 KB
testcase_21 AC 198 ms
6,656 KB
testcase_22 AC 85 ms
5,376 KB
testcase_23 AC 15 ms
5,376 KB
testcase_24 AC 24 ms
5,376 KB
testcase_25 AC 68 ms
5,376 KB
testcase_26 AC 420 ms
8,704 KB
testcase_27 AC 372 ms
8,064 KB
testcase_28 AC 230 ms
7,184 KB
testcase_29 AC 52 ms
5,376 KB
testcase_30 AC 315 ms
7,936 KB
testcase_31 AC 264 ms
7,052 KB
testcase_32 AC 109 ms
5,376 KB
testcase_33 AC 324 ms
8,320 KB
testcase_34 AC 22 ms
5,376 KB
testcase_35 AC 54 ms
5,376 KB
testcase_36 AC 26 ms
5,376 KB
testcase_37 AC 158 ms
5,504 KB
testcase_38 AC 8 ms
5,376 KB
testcase_39 AC 163 ms
5,504 KB
testcase_40 AC 35 ms
5,376 KB
testcase_41 AC 6 ms
5,376 KB
testcase_42 AC 397 ms
7,680 KB
testcase_43 AC 34 ms
6,708 KB
testcase_44 AC 249 ms
6,528 KB
testcase_45 AC 27 ms
5,376 KB
testcase_46 AC 30 ms
6,400 KB
testcase_47 AC 253 ms
6,400 KB
testcase_48 AC 255 ms
7,168 KB
testcase_49 AC 71 ms
5,376 KB
testcase_50 AC 5 ms
5,376 KB
testcase_51 AC 59 ms
5,376 KB
testcase_52 AC 110 ms
6,656 KB
testcase_53 AC 44 ms
5,376 KB
testcase_54 AC 41 ms
5,376 KB
testcase_55 AC 240 ms
8,620 KB
testcase_56 AC 294 ms
10,040 KB
testcase_57 AC 309 ms
10,348 KB
testcase_58 AC 155 ms
6,872 KB
testcase_59 AC 353 ms
11,212 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 n;

using P = pair<int, int>;

struct edge {
    int to;
    int cost;
};

vector<int> dist;
vector<vector<edge> > g;

void dijkstra(int s) {
    dist = vector<int>(n, Inf);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        rep (i, g[v].size()) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int m, q;
    cin >> n >> m;
    g = vector<vector<edge> >(n, vector<edge>());
    rep (i, m) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        edge e;
        e.to = t;
        e.cost = 1;
        g[s].push_back(e);
        e.to = s;
        g[t].push_back(e);
    }
    cin >> q;
    rep (x, q) {
        int a;
        cin >> a;
        a--;
        dijkstra(a);
        int cnt = 0;
        int day = 0;
        rep (i, n) {
            if (i == a) continue;
            if (dist[i] == Inf) continue;
            cnt++;
            int tmp = 0;
            dist[i]--;
            while (dist[i] > 0) {
                dist[i] /= 2;
                tmp++;
            }
            day = max(day, tmp);
        }
        cout << cnt << " " << day << endl;
    }
    
    return 0;
}

0