結果

問題 No.812 Change of Class
ユーザー granddaifukugranddaifuku
提出日時 2020-04-26 19:33:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 477 ms / 4,000 ms
コード長 1,843 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 177,332 KB
実行使用メモリ 11,148 KB
最終ジャッジ日時 2023-08-11 06:03:40
合計ジャッジ時間 16,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
8,120 KB
testcase_01 AC 14 ms
4,376 KB
testcase_02 AC 48 ms
5,776 KB
testcase_03 AC 101 ms
9,208 KB
testcase_04 AC 91 ms
8,332 KB
testcase_05 AC 473 ms
9,264 KB
testcase_06 AC 374 ms
8,516 KB
testcase_07 AC 4 ms
4,472 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 435 ms
9,908 KB
testcase_10 AC 444 ms
9,860 KB
testcase_11 AC 15 ms
7,084 KB
testcase_12 AC 265 ms
9,120 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 293 ms
7,344 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 262 ms
8,004 KB
testcase_18 AC 192 ms
6,460 KB
testcase_19 AC 221 ms
7,048 KB
testcase_20 AC 477 ms
9,388 KB
testcase_21 AC 183 ms
6,392 KB
testcase_22 AC 78 ms
4,684 KB
testcase_23 AC 14 ms
4,380 KB
testcase_24 AC 23 ms
4,376 KB
testcase_25 AC 63 ms
4,376 KB
testcase_26 AC 376 ms
8,800 KB
testcase_27 AC 320 ms
7,896 KB
testcase_28 AC 213 ms
7,212 KB
testcase_29 AC 49 ms
4,376 KB
testcase_30 AC 286 ms
7,840 KB
testcase_31 AC 247 ms
7,068 KB
testcase_32 AC 101 ms
5,140 KB
testcase_33 AC 300 ms
8,248 KB
testcase_34 AC 20 ms
4,376 KB
testcase_35 AC 52 ms
4,380 KB
testcase_36 AC 25 ms
4,376 KB
testcase_37 AC 147 ms
5,340 KB
testcase_38 AC 6 ms
4,756 KB
testcase_39 AC 149 ms
5,428 KB
testcase_40 AC 33 ms
4,384 KB
testcase_41 AC 6 ms
4,608 KB
testcase_42 AC 366 ms
7,592 KB
testcase_43 AC 33 ms
6,468 KB
testcase_44 AC 224 ms
6,136 KB
testcase_45 AC 25 ms
4,376 KB
testcase_46 AC 29 ms
6,224 KB
testcase_47 AC 220 ms
6,212 KB
testcase_48 AC 237 ms
7,060 KB
testcase_49 AC 66 ms
4,376 KB
testcase_50 AC 5 ms
4,380 KB
testcase_51 AC 53 ms
4,540 KB
testcase_52 AC 100 ms
6,480 KB
testcase_53 AC 41 ms
4,380 KB
testcase_54 AC 37 ms
4,380 KB
testcase_55 AC 217 ms
8,404 KB
testcase_56 AC 265 ms
9,764 KB
testcase_57 AC 284 ms
10,188 KB
testcase_58 AC 139 ms
6,556 KB
testcase_59 AC 323 ms
11,148 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,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