結果

問題 No.812 Change of Class
ユーザー 👑 emthrmemthrm
提出日時 2019-04-12 22:14:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,452 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 126,012 KB
実行使用メモリ 12,036 KB
最終ジャッジ日時 2023-09-03 12:46:31
合計ジャッジ時間 7,586 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
11,220 KB
testcase_01 AC 11 ms
7,020 KB
testcase_02 AC 28 ms
8,848 KB
testcase_03 AC 59 ms
12,036 KB
testcase_04 AC 52 ms
11,368 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
6,216 KB
testcase_08 AC 4 ms
6,236 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 10 ms
7,056 KB
testcase_12 WA -
testcase_13 AC 4 ms
6,152 KB
testcase_14 AC 4 ms
6,236 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 AC 20 ms
6,776 KB
testcase_36 AC 8 ms
6,428 KB
testcase_37 AC 47 ms
7,284 KB
testcase_38 AC 6 ms
6,472 KB
testcase_39 AC 50 ms
7,304 KB
testcase_40 AC 14 ms
6,556 KB
testcase_41 AC 5 ms
6,320 KB
testcase_42 AC 103 ms
8,236 KB
testcase_43 AC 21 ms
7,472 KB
testcase_44 AC 71 ms
7,864 KB
testcase_45 AC 9 ms
6,436 KB
testcase_46 AC 18 ms
7,632 KB
testcase_47 AC 69 ms
7,744 KB
testcase_48 AC 83 ms
7,920 KB
testcase_49 AC 19 ms
6,752 KB
testcase_50 AC 5 ms
6,188 KB
testcase_51 AC 22 ms
6,956 KB
testcase_52 AC 43 ms
7,636 KB
testcase_53 AC 13 ms
6,556 KB
testcase_54 AC 11 ms
6,520 KB
testcase_55 AC 27 ms
8,300 KB
testcase_56 AC 32 ms
8,708 KB
testcase_57 AC 34 ms
8,968 KB
testcase_58 AC 19 ms
7,712 KB
testcase_59 AC 37 ms
9,268 KB
testcase_60 AC 4 ms
6,176 KB
testcase_61 AC 4 ms
6,284 KB
testcase_62 AC 4 ms
6,184 KB
権限があれば一括ダウンロードができます

ソースコード

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 memo[100010];
void memo_init() {
  memo[0] = memo[1] = 0;
  int before = 2, now = 2, beki = 1;
  bool ok = true;
  while (ok) {
    FOR(i, before, now + 1) {
      if (i >= 100010) {
        ok = false;
        break;
      }
      memo[i] = beki;
    }
    before = now + 1;
    now <<= 1;
    ++beki;
  }
}

int day = 0;
vector<int> edge[100000];
bool used[100000] = {};
void dfs(int ver, int cnt) {
  day = max(day, memo[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);

  memo_init();
  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, 0);
    cout << uf.size(a) - 1 << ' ' << day << '\n';
  }
  return 0;
}
0