結果

問題 No.826 連絡網
ユーザー IKyoproIKyopro
提出日時 2019-05-03 21:44:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 66,508 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-08-15 18:11:17
合計ジャッジ時間 2,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 48 ms
8,656 KB
testcase_13 AC 18 ms
5,456 KB
testcase_14 AC 35 ms
7,336 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 22 ms
5,896 KB
testcase_17 AC 17 ms
5,112 KB
testcase_18 AC 13 ms
4,924 KB
testcase_19 AC 56 ms
9,844 KB
testcase_20 AC 54 ms
9,480 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 17 ms
5,512 KB
testcase_23 AC 23 ms
6,036 KB
testcase_24 AC 10 ms
4,416 KB
testcase_25 AC 67 ms
10,836 KB
testcase_26 AC 12 ms
4,732 KB
testcase_27 AC 49 ms
8,956 KB
testcase_28 AC 36 ms
7,508 KB
testcase_29 AC 17 ms
5,228 KB
testcase_30 AC 66 ms
10,932 KB
testcase_31 AC 21 ms
5,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class UnionFind{
private:
    vector<int> p,s;
public:
	UnionFind(){}
	UnionFind(int N){
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
};

int N,P;
int main(){
    cin >> N >> P;
    UnionFind uf(N);
    for(int i=2;i<=N;i++) for(int j=1;i*j<=N;j++) uf.unite(i,i*j);
    cout << uf.size(P) << endl;
}
0