結果

問題 No.826 連絡網
ユーザー Mr.SpockMr.Spock
提出日時 2021-02-10 02:59:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 169,916 KB
実行使用メモリ 11,140 KB
最終ジャッジ日時 2023-09-21 18:16:44
合計ジャッジ時間 2,897 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 22 ms
8,700 KB
testcase_13 AC 9 ms
5,352 KB
testcase_14 AC 18 ms
7,216 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 12 ms
5,864 KB
testcase_17 AC 9 ms
5,396 KB
testcase_18 AC 8 ms
4,828 KB
testcase_19 AC 27 ms
9,832 KB
testcase_20 AC 26 ms
9,572 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 9 ms
5,348 KB
testcase_23 AC 13 ms
6,152 KB
testcase_24 AC 6 ms
4,412 KB
testcase_25 AC 33 ms
11,088 KB
testcase_26 AC 7 ms
4,604 KB
testcase_27 AC 24 ms
9,180 KB
testcase_28 AC 19 ms
7,844 KB
testcase_29 AC 9 ms
5,336 KB
testcase_30 AC 32 ms
11,140 KB
testcase_31 AC 11 ms
5,956 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;
vector<int>s;
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);
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, node;
	cin >> n >> node;
	par.resize(n + 1);
	s.resize(n + 1);
	iota(par.begin(), par.end(), 0);
	fill(s.begin(), s.end(), 1);
	prepare(n);
	cout << s[get(node)] << endl;
}
0