結果

問題 No.826 連絡網
ユーザー yuppe19 😺yuppe19 😺
提出日時 2019-05-29 11:34:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 69,888 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-05-03 05:22:53
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 36 ms
6,016 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 27 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 43 ms
6,528 KB
testcase_20 AC 41 ms
6,400 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 8 ms
5,376 KB
testcase_25 AC 52 ms
7,040 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 38 ms
6,144 KB
testcase_28 AC 29 ms
5,504 KB
testcase_29 AC 13 ms
5,376 KB
testcase_30 AC 51 ms
7,168 KB
testcase_31 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

class UnionFind {
  vector<int> par;
 public:
  explicit UnionFind(int n) : par(n, -1) {}
  int root(int a) {
    if(par[a] < 0) { return a; }
    return par[a] = root(par[a]);
  }
  int size(int a) {
    return -par[root(a)];
  }
  void unite(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b) { return; }
    if(size(a) < size(b)) { swap(a, b); }
    par[a] += par[b];
    par[b] = a;
  }
};

int f(int N, int P) {
  UnionFind uf(N+1);
  for(int i=2; i<=N; ++i) {
    for(int j=i+i; j<=N; j+=i) {
      uf.unite(i, j);
    }
  }
  return uf.size(P);
}

int main(void) {
  int N, P; scanf("%d%d", &N, &P);
  int res = f(N, P);
  printf("%d\n", res);
  return 0;
}
0