結果

問題 No.812 Change of Class
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-27 16:55:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,894 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 179,704 KB
実行使用メモリ 14,680 KB
最終ジャッジ日時 2023-09-03 15:36:19
合計ジャッジ時間 8,930 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
12,544 KB
testcase_01 AC 16 ms
4,524 KB
testcase_02 AC 54 ms
8,436 KB
testcase_03 AC 121 ms
14,680 KB
testcase_04 AC 106 ms
13,124 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 14 ms
6,728 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 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 24 ms
4,380 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 63 ms
5,000 KB
testcase_38 AC 6 ms
4,608 KB
testcase_39 AC 65 ms
5,000 KB
testcase_40 AC 15 ms
4,376 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 145 ms
6,688 KB
testcase_43 AC 33 ms
5,892 KB
testcase_44 AC 93 ms
5,776 KB
testcase_45 AC 9 ms
4,376 KB
testcase_46 AC 30 ms
6,064 KB
testcase_47 AC 91 ms
5,820 KB
testcase_48 AC 105 ms
6,724 KB
testcase_49 AC 23 ms
4,380 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 27 ms
4,380 KB
testcase_52 AC 58 ms
6,200 KB
testcase_53 AC 15 ms
4,376 KB
testcase_54 AC 13 ms
4,376 KB
testcase_55 AC 50 ms
7,292 KB
testcase_56 AC 58 ms
7,772 KB
testcase_57 AC 61 ms
8,216 KB
testcase_58 AC 33 ms
5,668 KB
testcase_59 AC 70 ms
8,940 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

//UnionFind
class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

vector<vector<int>> G;
vector<bool> visited;

int dist(int v, int p = -1) {
    int res = 0;
    for (int u : G[v]) {
        if (u == p || visited[u]) continue;
        visited[u] = true;
        res = max(res,dist(u, v)+1);
    }
    return res;
}

int f(int n) {
    int res = 0;
    int k = 1;
    while (n > k) {
        res++;
        k <<= 1;
    }
    return res;
}

int main() {
    int n, m; 
    cin >> n >> m;
    UnionFind uni(n);
    G.resize(n);
    visited.resize(n, false);
    REP(i, m) {
        int p, q; cin >> p >> q;
        p--; q--;
        G[p].push_back(q);
        G[q].push_back(p);
        uni.unite(p, q);
    }
    int Q; cin >> Q;
    REP(i, Q) {
        int a; cin >> a;
        a--;
        visited = vector<bool>(n, false);
        cout << uni.size(a)-1 << " " << f(dist(a)) << endl;
    }
    getchar(); getchar();
}
0