結果

問題 No.812 Change of Class
ユーザー pekempeypekempey
提出日時 2019-04-14 17:40:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 4,000 ms
コード長 810 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 83,948 KB
実行使用メモリ 9,500 KB
最終ジャッジ日時 2023-09-03 15:03:55
合計ジャッジ時間 7,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
7,812 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 41 ms
5,640 KB
testcase_03 AC 86 ms
8,616 KB
testcase_04 AC 77 ms
7,844 KB
testcase_05 AC 171 ms
7,904 KB
testcase_06 AC 151 ms
6,660 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 159 ms
8,600 KB
testcase_10 AC 165 ms
8,664 KB
testcase_11 AC 15 ms
6,600 KB
testcase_12 AC 109 ms
8,260 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 112 ms
6,736 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 107 ms
7,032 KB
testcase_18 AC 81 ms
5,924 KB
testcase_19 AC 94 ms
6,424 KB
testcase_20 AC 170 ms
8,396 KB
testcase_21 AC 75 ms
5,620 KB
testcase_22 AC 34 ms
4,388 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 27 ms
4,376 KB
testcase_26 AC 134 ms
7,636 KB
testcase_27 AC 122 ms
7,180 KB
testcase_28 AC 87 ms
6,316 KB
testcase_29 AC 20 ms
4,376 KB
testcase_30 AC 111 ms
6,996 KB
testcase_31 AC 94 ms
6,272 KB
testcase_32 AC 43 ms
4,556 KB
testcase_33 AC 115 ms
7,340 KB
testcase_34 AC 9 ms
4,380 KB
testcase_35 AC 22 ms
4,380 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 53 ms
4,896 KB
testcase_38 AC 6 ms
4,688 KB
testcase_39 AC 53 ms
5,024 KB
testcase_40 AC 14 ms
4,376 KB
testcase_41 AC 4 ms
4,396 KB
testcase_42 AC 112 ms
6,776 KB
testcase_43 AC 30 ms
5,868 KB
testcase_44 AC 76 ms
5,840 KB
testcase_45 AC 9 ms
4,380 KB
testcase_46 AC 28 ms
5,868 KB
testcase_47 AC 76 ms
5,656 KB
testcase_48 AC 85 ms
6,424 KB
testcase_49 AC 23 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 25 ms
4,380 KB
testcase_52 AC 52 ms
6,168 KB
testcase_53 AC 15 ms
4,380 KB
testcase_54 AC 12 ms
4,380 KB
testcase_55 AC 55 ms
7,416 KB
testcase_56 AC 65 ms
8,252 KB
testcase_57 AC 69 ms
8,428 KB
testcase_58 AC 36 ms
5,880 KB
testcase_59 AC 79 ms
9,500 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int A;
    cin >> A;
    A--;
    vector<int> d(N, -1);
    d[A] = 0;
    queue<int> q;
    q.push(A);
    int c = 0;
    int m = 0;
    while (!q.empty()) {
      int u = q.front(); q.pop();
      c++;
      m = max(m, d[u]);
      for (int v : G[u]) if (d[v] == -1) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
    int k = 1;
    int ans = 0;
    while (k < m) k *= 2, ans++;
    cout << c-1 << ' ' << ans << '\n';
  }
}
0