結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  kyort0n | 
| 提出日時 | 2019-05-03 21:27:35 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 82 ms / 2,000 ms | 
| コード長 | 1,421 bytes | 
| コンパイル時間 | 1,941 ms | 
| コンパイル使用メモリ | 172,604 KB | 
| 実行使用メモリ | 18,816 KB | 
| 最終ジャッジ日時 | 2024-11-24 02:13:47 | 
| 合計ジャッジ時間 | 3,706 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }
    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }
    ll size(int x){
        return Size[root(x)];
    }
};
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    UnionFind uni(1000500);
    for(int i = 2; i <= N; i++) {
        for(int j = 2 * i; j <= N; j += i) {
            uni.merge(j, j - i);
        }
    }
    cout << uni.size(P) << endl;
    return 0;
}
            
            
            
        