結果

問題 No.812 Change of Class
ユーザー simansiman
提出日時 2021-05-30 16:55:51
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 143,424 KB
実行使用メモリ 9,848 KB
最終ジャッジ日時 2024-04-26 07:48:32
合計ジャッジ時間 7,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 14 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 7 ms
6,944 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 6 ms
6,944 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 72 ms
8,448 KB
testcase_56 AC 83 ms
8,972 KB
testcase_57 AC 91 ms
9,212 KB
testcase_58 AC 46 ms
7,676 KB
testcase_59 AC 98 ms
9,848 KB
testcase_60 AC 3 ms
6,944 KB
testcase_61 AC 3 ms
6,940 KB
testcase_62 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int v;
  int dist;

  Node(int v = -1, int dist = -1) {
    this->v = v;
    this->dist = dist;
  }
};

const int MAX_N = 100010;

vector<int> E[MAX_N];

int main() {
  int N, M;
  cin >> N >> M;

  int p, q;
  for (int i = 0; i < M; ++i) {
    cin >> p >> q;
    E[p].push_back(q);
    E[q].push_back(p);
  }

  int Q;
  cin >> Q;
  int A;

  for (int i = 0; i < Q; ++i) {
    cin >> A;
    queue<Node> que;
    que.push(Node(A, 0));

    bool visited[N + 1];
    memset(visited, false, sizeof(visited));
    int cnt = 0;
    int max_dist = 0;

    while (not que.empty()) {
      Node node = que.front();
      que.pop();

      if (visited[node.v]) continue;
      visited[node.v] = true;
      ++cnt;
      max_dist = max(max_dist, node.dist);

      for (int u : E[node.v]) {
        que.push(Node(u, node.dist + 1));
      }
    }

    if (max_dist <= 1) {
      cout << cnt - 1 << " " << 0 << endl;
    } else {
      cout << cnt - 1 << " " << max(0, (int) ceil(max_dist / 2.0)) << endl;
    }
  }

  return 0;
}
0