結果

問題 No.826 連絡網
ユーザー kappybarkappybar
提出日時 2020-04-12 12:07:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,478 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 172,512 KB
実行使用メモリ 22,176 KB
最終ジャッジ日時 2023-10-22 00:57:52
合計ジャッジ時間 3,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 64 ms
16,964 KB
testcase_13 AC 23 ms
8,584 KB
testcase_14 AC 46 ms
13,336 KB
testcase_15 AC 6 ms
4,624 KB
testcase_16 AC 30 ms
10,168 KB
testcase_17 AC 23 ms
8,584 KB
testcase_18 AC 18 ms
7,528 KB
testcase_19 AC 84 ms
19,076 KB
testcase_20 AC 80 ms
18,812 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 23 ms
8,848 KB
testcase_23 AC 31 ms
10,432 KB
testcase_24 AC 13 ms
6,472 KB
testcase_25 AC 110 ms
21,912 KB
testcase_26 AC 16 ms
7,000 KB
testcase_27 AC 67 ms
17,228 KB
testcase_28 AC 50 ms
14,128 KB
testcase_29 AC 23 ms
8,584 KB
testcase_30 AC 110 ms
22,176 KB
testcase_31 AC 28 ms
9,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const int INF = 1e9;
const int MOD = 1000000007;

ll gcd(ll i,ll j){
        if(j == 0) return i;
        return gcd(j,i%j);
}

struct Unionfind{
    vector<int> parents;
    int m;
    Unionfind(int n):parents(n,-1){
        m = n;
    }

    int find(int x){
        if(parents.at(x) < 0){
            return x;
        }else{
            parents.at(x) = find(parents.at(x));
            return parents.at(x);
        }
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x==y) return;
        if(parents.at(x) > parents.at(x))swap(x,y);
        parents.at(x) += parents.at(y);
        parents.at(y) = x;
    }  

   int size(int x){
       return -parents.at(find(x));
   }

   bool same(int x,int y){
       return find(x) ==find(y);
   }

   vector<int> members(int x){
       int root = find(x);
       vector<int> A;
       for(int i=0;i<m;i++){
           if(find(i) ==root ){
               A.push_back(i);
           }
       }
      return A;
  }
};

int main(){
    int n,p;
    cin >> n >> p;
    Unionfind uf(n+5);
    vector<int> f(n+5,0);
    f[0] = f[1] = -1;
    for(int i=2;i<=n;i++){
        if(f[i]) continue;
        for(int j=i;j<=n;j+=i){
            f[j] = i;
            if(j==i) continue;
            uf.unite(j,j-i);
        }
    }
    cout << uf.size(p) << endl;
    return 0;
}
0