結果
問題 | No.826 連絡網 |
ユーザー | siman |
提出日時 | 2021-08-05 16:57:02 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 3,787 ms |
コンパイル使用メモリ | 105,804 KB |
実行使用メモリ | 16,484 KB |
最終ジャッジ日時 | 2023-10-14 21:37:19 |
合計ジャッジ時間 | 3,506 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
15,960 KB |
testcase_01 | AC | 19 ms
16,016 KB |
testcase_02 | AC | 19 ms
15,844 KB |
testcase_03 | AC | 20 ms
15,808 KB |
testcase_04 | AC | 20 ms
15,964 KB |
testcase_05 | AC | 20 ms
16,092 KB |
testcase_06 | AC | 20 ms
15,916 KB |
testcase_07 | AC | 19 ms
15,888 KB |
testcase_08 | AC | 19 ms
16,000 KB |
testcase_09 | AC | 19 ms
15,872 KB |
testcase_10 | AC | 19 ms
15,904 KB |
testcase_11 | AC | 19 ms
15,940 KB |
testcase_12 | AC | 50 ms
15,928 KB |
testcase_13 | AC | 29 ms
16,068 KB |
testcase_14 | AC | 39 ms
15,992 KB |
testcase_15 | AC | 21 ms
15,848 KB |
testcase_16 | AC | 31 ms
15,996 KB |
testcase_17 | AC | 28 ms
16,032 KB |
testcase_18 | AC | 25 ms
15,924 KB |
testcase_19 | AC | 58 ms
15,948 KB |
testcase_20 | AC | 54 ms
15,788 KB |
testcase_21 | AC | 19 ms
15,992 KB |
testcase_22 | AC | 28 ms
16,016 KB |
testcase_23 | AC | 31 ms
16,016 KB |
testcase_24 | AC | 24 ms
16,072 KB |
testcase_25 | AC | 69 ms
16,484 KB |
testcase_26 | AC | 25 ms
15,940 KB |
testcase_27 | AC | 48 ms
15,880 KB |
testcase_28 | AC | 40 ms
15,884 KB |
testcase_29 | AC | 28 ms
16,012 KB |
testcase_30 | AC | 70 ms
15,964 KB |
testcase_31 | AC | 30 ms
15,980 KB |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 1000010; vector<int> parent; vector<int> _rank; vector<int> _size; class UnionFind { public: UnionFind(int n) { for (int i = 0; i < n; ++i) { parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { parent[x] = y; _size[y] += _size[x]; } else { parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; int main() { int N, P; cin >> N >> P; UnionFind uf(MAX_N); bool visited[MAX_N]; memset(visited, false, sizeof(visited)); for (int i = 2; i <= N; ++i) { if (visited[i]) continue; visited[i] = true; for (int j = 2 * i; j <= N; j += i) { visited[j] = true; uf.unite(i, j); } } cout << uf.size(P) << endl; return 0; }