結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  IKyopro | 
| 提出日時 | 2019-05-03 21:44:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 71 ms / 2,000 ms | 
| コード長 | 754 bytes | 
| コンパイル時間 | 646 ms | 
| コンパイル使用メモリ | 67,848 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-11-24 02:15:53 | 
| 合計ジャッジ時間 | 2,197 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#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;
}
            
            
            
        