結果

問題 No.812 Change of Class
ユーザー 👑 emthrmemthrm
提出日時 2019-04-12 21:50:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,098 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 127,104 KB
実行使用メモリ 11,816 KB
最終ジャッジ日時 2023-09-03 01:21:39
合計ジャッジ時間 7,154 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
5,820 KB
testcase_08 AC 4 ms
5,948 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
5,880 KB
testcase_14 AC 3 ms
5,748 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 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 5 ms
5,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 29 ms
7,960 KB
testcase_56 AC 34 ms
8,364 KB
testcase_57 AC 36 ms
8,644 KB
testcase_58 AC 21 ms
7,112 KB
testcase_59 AC 40 ms
8,960 KB
testcase_60 AC 3 ms
5,824 KB
testcase_61 AC 4 ms
5,824 KB
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
struct UnionFind {
  UnionFind(int sz) : data(sz, -1) {}

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  void unite(int ver1, int ver2) {
    ver1 = root(ver1);
    ver2 = root(ver2);
    if (ver1 != ver2) {
      if (data[ver1] > data[ver2]) swap(ver1, ver2);
      data[ver1] += data[ver2];
      data[ver2] = ver1;
    }
  }

  bool same(int ver1, int ver2) { return root(ver1) == root(ver2); }

  int size(int ver) { return -data[root(ver)]; }

private:
  vector<int> data;
};

int day = 0;
vector<int> edge[100000];
bool used[100000] = {};
void dfs(int ver, int cnt) {
  day = max(day, cnt);
  for (int e : edge[ver]) if (!used[e]) {
    used[e] = true;
    dfs(e, cnt + 1);
  }
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  UnionFind uf(n);
  while (m--) {
    int p, q; cin >> p >> q; --p; --q;
    uf.unite(p, q);
    edge[p].emplace_back(q);
    edge[q].emplace_back(p);
  }
  int q; cin >> q;
  while (q--) {
    int a; cin >> a; --a;
    day = 0;
    memset(used, false, sizeof(used));
    used[a] = true;
    dfs(a, -1);
    cout << uf.size(a) - 1 << ' ' << day << '\n';
  }
  return 0;
}
0