結果

問題 No.826 連絡網
ユーザー beetbeet
提出日時 2019-05-03 21:34:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 201,352 KB
実行使用メモリ 18,500 KB
最終ジャッジ日時 2023-08-15 18:10:38
合計ジャッジ時間 3,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 42 ms
14,492 KB
testcase_13 AC 16 ms
7,468 KB
testcase_14 AC 30 ms
11,460 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 19 ms
8,896 KB
testcase_17 AC 16 ms
7,452 KB
testcase_18 AC 12 ms
6,412 KB
testcase_19 AC 52 ms
15,936 KB
testcase_20 AC 48 ms
16,044 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 17 ms
7,620 KB
testcase_23 AC 20 ms
8,792 KB
testcase_24 AC 9 ms
5,744 KB
testcase_25 AC 69 ms
18,464 KB
testcase_26 AC 12 ms
6,264 KB
testcase_27 AC 43 ms
14,592 KB
testcase_28 AC 31 ms
12,188 KB
testcase_29 AC 16 ms
7,624 KB
testcase_30 AC 66 ms
18,500 KB
testcase_31 AC 18 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
  Int size(Int x){
    return r[find(x)];
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,p;
  cin>>n>>p;
  UnionFind uf(n+1);
  for(Int i=2;i<=n;i++){
    for(Int j=i;j<=n;j+=i){
      uf.unite(i,j);
    }
  }  
  cout<<uf.size(p)<<endl;
  return 0;
}
0