結果

問題 No.826 連絡網
ユーザー firiexpfiriexp
提出日時 2019-05-03 21:35:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 95,252 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2023-08-15 23:52:33
合計ジャッジ時間 3,097 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 34 ms
5,904 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 25 ms
5,292 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 15 ms
4,492 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 39 ms
6,344 KB
testcase_20 AC 37 ms
6,100 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 16 ms
4,384 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 46 ms
6,940 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 34 ms
5,948 KB
testcase_28 AC 25 ms
5,156 KB
testcase_29 AC 11 ms
4,380 KB
testcase_30 AC 47 ms
6,896 KB
testcase_31 AC 15 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n, p;
    cin >> n >> p;
    UnionFind uf(n);
    for (int i = 2; i <= n; ++i) {
        for (int j = i*2; j <= n; j += i) {
            uf.unite(i-1, j-1);
        }
    }
    cout << uf.size(p-1) << "\n";
    return 0;
}
0