結果

問題 No.812 Change of Class
ユーザー kk
提出日時 2020-09-02 20:55:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 4,000 ms
コード長 1,149 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 206,992 KB
実行使用メモリ 9,616 KB
最終ジャッジ日時 2024-05-01 15:28:29
合計ジャッジ時間 7,691 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
8,576 KB
testcase_01 AC 10 ms
6,400 KB
testcase_02 AC 27 ms
7,296 KB
testcase_03 AC 55 ms
9,088 KB
testcase_04 AC 49 ms
8,576 KB
testcase_05 AC 133 ms
8,704 KB
testcase_06 AC 112 ms
8,320 KB
testcase_07 AC 4 ms
6,016 KB
testcase_08 AC 4 ms
5,888 KB
testcase_09 AC 123 ms
9,216 KB
testcase_10 AC 122 ms
9,088 KB
testcase_11 AC 10 ms
7,040 KB
testcase_12 AC 77 ms
8,704 KB
testcase_13 AC 3 ms
5,888 KB
testcase_14 AC 4 ms
5,888 KB
testcase_15 AC 85 ms
7,936 KB
testcase_16 AC 8 ms
6,144 KB
testcase_17 AC 79 ms
7,936 KB
testcase_18 AC 59 ms
7,552 KB
testcase_19 AC 67 ms
7,808 KB
testcase_20 AC 127 ms
8,960 KB
testcase_21 AC 58 ms
7,296 KB
testcase_22 AC 28 ms
6,528 KB
testcase_23 AC 8 ms
6,016 KB
testcase_24 AC 10 ms
6,144 KB
testcase_25 AC 23 ms
6,272 KB
testcase_26 AC 103 ms
8,448 KB
testcase_27 AC 94 ms
8,192 KB
testcase_28 AC 64 ms
7,804 KB
testcase_29 AC 17 ms
6,400 KB
testcase_30 AC 80 ms
8,064 KB
testcase_31 AC 69 ms
7,748 KB
testcase_32 AC 34 ms
6,912 KB
testcase_33 AC 86 ms
8,192 KB
testcase_34 AC 9 ms
5,888 KB
testcase_35 AC 18 ms
6,400 KB
testcase_36 AC 10 ms
6,144 KB
testcase_37 AC 41 ms
7,040 KB
testcase_38 AC 6 ms
6,272 KB
testcase_39 AC 44 ms
7,040 KB
testcase_40 AC 13 ms
6,144 KB
testcase_41 AC 6 ms
6,144 KB
testcase_42 AC 81 ms
8,192 KB
testcase_43 AC 19 ms
7,168 KB
testcase_44 AC 60 ms
7,424 KB
testcase_45 AC 9 ms
6,016 KB
testcase_46 AC 17 ms
7,424 KB
testcase_47 AC 58 ms
7,552 KB
testcase_48 AC 65 ms
7,808 KB
testcase_49 AC 17 ms
6,272 KB
testcase_50 AC 4 ms
5,888 KB
testcase_51 AC 19 ms
6,656 KB
testcase_52 AC 37 ms
7,552 KB
testcase_53 AC 15 ms
6,400 KB
testcase_54 AC 12 ms
6,272 KB
testcase_55 AC 32 ms
8,576 KB
testcase_56 AC 38 ms
8,852 KB
testcase_57 AC 40 ms
9,088 KB
testcase_58 AC 22 ms
7,680 KB
testcase_59 AC 43 ms
9,616 KB
testcase_60 AC 3 ms
5,760 KB
testcase_61 AC 3 ms
5,888 KB
testcase_62 AC 3 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

const int INF = 1<<28;
int n, m;
vector<int> edges[100000];
int dist[100000];

int ceil_log(int x) {
  int r = log2(x);
  if (1<<r < x)
    ++r;
  return r;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m;
  REP (i, m) {
    int p, q;
    cin >> p >> q;
    --p, --q;
    edges[p].push_back(q);
    edges[q].push_back(p);
  }

  int q;
  cin >> q;
  while (q--) {
    int v;
    cin >> v;
    --v;
    fill(dist, dist + n, INF);

    queue<int> que;
    que.push(v);
    dist[v] = 0;
    int c = 0;
    int d = 0;
    
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      ++c;
      d = max(d, dist[u]);

      for (int w: edges[u]) {
        if (dist[w] == INF) {
          dist[w] = dist[u] + 1;
          que.push(w);
        }
      }
    }

    if (!--c)
      cout << 0 << " " << 0 << endl;
    else
      cout << c << " " << ceil_log(d) << endl;
  }
  
  return 0;
}
0