結果

問題 No.826 連絡網
ユーザー Mr.SpockMr.Spock
提出日時 2021-02-10 02:57:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 168,416 KB
実行使用メモリ 11,088 KB
最終ジャッジ日時 2023-09-21 18:15:20
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,744 KB
testcase_01 AC 7 ms
10,812 KB
testcase_02 AC 7 ms
10,784 KB
testcase_03 AC 6 ms
11,064 KB
testcase_04 AC 6 ms
10,996 KB
testcase_05 AC 7 ms
10,724 KB
testcase_06 AC 5 ms
11,052 KB
testcase_07 AC 6 ms
10,672 KB
testcase_08 AC 6 ms
10,976 KB
testcase_09 AC 7 ms
10,732 KB
testcase_10 AC 6 ms
11,076 KB
testcase_11 AC 6 ms
10,896 KB
testcase_12 AC 23 ms
10,740 KB
testcase_13 AC 12 ms
11,028 KB
testcase_14 AC 18 ms
10,872 KB
testcase_15 AC 7 ms
11,088 KB
testcase_16 AC 14 ms
11,064 KB
testcase_17 AC 13 ms
10,888 KB
testcase_18 AC 11 ms
10,940 KB
testcase_19 AC 27 ms
10,888 KB
testcase_20 AC 26 ms
10,896 KB
testcase_21 AC 7 ms
10,780 KB
testcase_22 AC 12 ms
11,032 KB
testcase_23 AC 14 ms
10,940 KB
testcase_24 AC 8 ms
10,980 KB
testcase_25 AC 33 ms
10,888 KB
testcase_26 AC 10 ms
11,028 KB
testcase_27 AC 25 ms
11,028 KB
testcase_28 AC 18 ms
10,932 KB
testcase_29 AC 12 ms
11,024 KB
testcase_30 AC 31 ms
10,892 KB
testcase_31 AC 14 ms
10,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 1e6 + 7;
vector<bool>prime(nax, true);
vector<int>par(nax);
vector<int>s(nax);
int get(int x) {
	if (x == par[x])return x;
	return (par[x] = get(par[x]));
}
bool modify(int x, int y) {
	x = get(x);
	y = get(y);
	if (x == y)return true;
	if (s[y] > s[x]) swap(x, y);
	par[y] = x;
	s[x] += s[y];
	return false;
}
void prepare(int n) {
	for (int i = 2; i <= n; i++) {
		if (prime[i]) {
			for (int j = 2; (j * i) <= n; j++) {
				prime[j * i] = false;
				modify(i * j, i);
				// cout << i << " " << i*j << endl;
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, node;
	cin >> n >> node;
	iota(par.begin(), par.end(), 0);
	fill(s.begin(), s.end(), 1);
	prepare(n);
	cout << s[get(node)] << endl;
}
0