結果

問題 No.826 連絡網
ユーザー kazumakazuma
提出日時 2019-05-03 21:31:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 203,880 KB
実行使用メモリ 7,080 KB
最終ジャッジ日時 2024-05-03 05:00:26
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 41 ms
6,940 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 30 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 19 ms
6,940 KB
testcase_17 AC 15 ms
6,944 KB
testcase_18 AC 11 ms
6,940 KB
testcase_19 AC 46 ms
6,944 KB
testcase_20 AC 45 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 15 ms
6,940 KB
testcase_23 AC 20 ms
6,940 KB
testcase_24 AC 9 ms
6,944 KB
testcase_25 AC 56 ms
7,072 KB
testcase_26 AC 10 ms
6,944 KB
testcase_27 AC 41 ms
6,940 KB
testcase_28 AC 30 ms
6,944 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 55 ms
7,080 KB
testcase_31 AC 18 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

class union_find {
	vector<int> par;
public:
	union_find(int n) : par(n, -1) {}
	int find(int a) {
		return par[a] < 0 ? a : par[a] = find(par[a]);
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (par[a] < par[b]) {
			par[a] += par[b];
			par[b] = a;
		}
		else {
			par[b] += par[a];
			par[a] = b;
		}
	}
	int size(int a) {
		return -par[find(a)];
	}
};

int main()
{
	int N, P;
	cin >> N >> P;
	union_find 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