結果

問題 No.826 連絡網
ユーザー treeonetreeone
提出日時 2019-05-03 21:33:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 201,624 KB
実行使用メモリ 18,788 KB
最終ジャッジ日時 2023-08-15 18:10:33
合計ジャッジ時間 3,542 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 22 ms
14,368 KB
testcase_13 AC 9 ms
7,540 KB
testcase_14 AC 15 ms
11,360 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 11 ms
8,568 KB
testcase_17 AC 9 ms
7,472 KB
testcase_18 AC 7 ms
6,612 KB
testcase_19 AC 23 ms
16,316 KB
testcase_20 AC 22 ms
15,948 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 9 ms
7,604 KB
testcase_23 AC 11 ms
8,740 KB
testcase_24 AC 6 ms
5,640 KB
testcase_25 AC 27 ms
18,696 KB
testcase_26 AC 7 ms
6,256 KB
testcase_27 AC 20 ms
14,692 KB
testcase_28 AC 16 ms
12,092 KB
testcase_29 AC 9 ms
7,504 KB
testcase_30 AC 27 ms
18,788 KB
testcase_31 AC 10 ms
8,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct UF{
    vector<int> par, sz;
    UF(){}
    UF(int n):par(n), sz(n, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    UF uf(n + 1);
    for(int i = 2; i <= n; i++){
        if(uf.find(i) != i) continue;
        for(int j = 2 * i; j <= n; j += i){
            uf.unite(uf.find(i), uf.find(j));
        }
    }
    cout << uf.sz[uf.find(p)] << endl;
}
0