結果

問題 No.812 Change of Class
ユーザー 0w10w1
提出日時 2020-11-16 15:17:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 646 ms / 4,000 ms
コード長 1,291 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 210,224 KB
実行使用メモリ 13,624 KB
最終ジャッジ日時 2023-09-30 07:18:05
合計ジャッジ時間 19,027 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
8,232 KB
testcase_01 AC 19 ms
4,376 KB
testcase_02 AC 67 ms
5,760 KB
testcase_03 AC 141 ms
8,920 KB
testcase_04 AC 123 ms
8,356 KB
testcase_05 AC 646 ms
9,740 KB
testcase_06 AC 521 ms
9,292 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 536 ms
10,312 KB
testcase_10 AC 593 ms
10,420 KB
testcase_11 AC 11 ms
7,000 KB
testcase_12 AC 307 ms
9,228 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 390 ms
8,008 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 335 ms
8,416 KB
testcase_18 AC 259 ms
6,504 KB
testcase_19 AC 288 ms
7,400 KB
testcase_20 AC 620 ms
10,132 KB
testcase_21 AC 248 ms
6,536 KB
testcase_22 AC 103 ms
5,212 KB
testcase_23 AC 17 ms
4,380 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 83 ms
4,852 KB
testcase_26 AC 475 ms
9,268 KB
testcase_27 AC 419 ms
8,404 KB
testcase_28 AC 271 ms
7,296 KB
testcase_29 AC 62 ms
4,536 KB
testcase_30 AC 371 ms
8,196 KB
testcase_31 AC 322 ms
6,928 KB
testcase_32 AC 130 ms
5,592 KB
testcase_33 AC 383 ms
8,852 KB
testcase_34 AC 27 ms
4,380 KB
testcase_35 AC 65 ms
4,380 KB
testcase_36 AC 33 ms
4,376 KB
testcase_37 AC 190 ms
5,184 KB
testcase_38 AC 5 ms
4,584 KB
testcase_39 AC 196 ms
5,276 KB
testcase_40 AC 42 ms
4,376 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 392 ms
7,708 KB
testcase_43 AC 29 ms
6,376 KB
testcase_44 AC 282 ms
6,144 KB
testcase_45 AC 34 ms
4,504 KB
testcase_46 AC 28 ms
6,012 KB
testcase_47 AC 274 ms
6,236 KB
testcase_48 AC 258 ms
7,280 KB
testcase_49 AC 88 ms
4,472 KB
testcase_50 AC 6 ms
4,380 KB
testcase_51 AC 68 ms
4,764 KB
testcase_52 AC 117 ms
6,888 KB
testcase_53 AC 56 ms
4,380 KB
testcase_54 AC 49 ms
4,376 KB
testcase_55 AC 422 ms
10,776 KB
testcase_56 AC 499 ms
12,224 KB
testcase_57 AC 530 ms
12,380 KB
testcase_58 AC 256 ms
8,128 KB
testcase_59 AC 597 ms
13,624 KB
testcase_60 AC 1 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;

template<typename T, T INF>
vector<T> dijkstra(const vector<vector<pair<int, int>>> &g, int st = 0) {
  const int n = g.size();
  vector<T> dis(n, INF); {
    set<pair<T, int>> bag;
    bag.emplace(dis[st] = 0, st);
    while (bag.size()) {
      auto [d, u] = *bag.begin();
      bag.erase(bag.begin());
      if (d != dis[u]) continue;
      for (auto [w, v] : g[u]) {
        if (d + w < dis[v]) {
          bag.emplace(dis[v] = d + w, v);
        }
      }
    }
  }
  return dis;
}

int main() {
  ios::sync_with_stdio(false);

  int N, M; {
    cin >> N >> M;
  }

  vector<vector<pair<int, int>>> G(N); {
    for (int i = 0; i < M; ++i) {
      int U, V; {
        cin >> U >> V;
        --U, --V;
      }
      G[U].emplace_back(1, V);
      G[V].emplace_back(1, U);
    }
  }

  int Q; { cin >> Q; }

  while (Q--) {
    int A; {
      cin >> A;
      --A;
    }

    int cnt = 0;
    int maxd = 0; {
      const int INF = 0x3f3f3f3f;
      auto dis = dijkstra<int, INF>(G, A);
      for (int u = 0; u < N; ++u) if (u != A) {
        if (dis[u] == INF) continue;
        ++cnt;
        maxd = max(maxd, dis[u]);
      }
    }

    auto f = [](int d) { return d ? ceil(log2(d)) : 0; };

    cout << cnt << ' ' << f(maxd) << endl;
  }
}
0