結果
| 問題 | No.826 連絡網 |
| コンテスト | |
| ユーザー |
ninoinui
|
| 提出日時 | 2020-07-18 09:17:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 874 bytes |
| 記録 | |
| コンパイル時間 | 3,041 ms |
| コンパイル使用メモリ | 198,588 KB |
| 最終ジャッジ日時 | 2025-01-12 00:10:03 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
int sz;
vector<int> par, siz;
public:
UnionFind() {}
UnionFind(int n) : sz(n), par(sz), siz(sz, 1) {
iota(par.begin(), par.end(), 0);
}
int root(int x) {
if (par.at(x) == x) return x;
else return par.at(x) = root(par.at(x));
}
void unit(int x,int y) {
x = root(x), y = root(y);
if (x == y) return;
if (siz.at(x) < siz.at(y)) swap(x, y);
par.at(y) = x;
siz.at(x) += siz.at(y);
}
int size(int x) {
x = root(x);
return siz.at(x);
}
bool same(int x, int y) {
return root(x) == root(y);
}
};
int main() {
int N, P;
cin >> N >> P;
UnionFind UF(N + 1);
for (int i = 2; i <= N; i++) {
for (int j = i + i; j <= N; j += i) {
if (UF.same(j - i, j)) break;
UF.unit(j - i, j);
}
}
cout << UF.size(P) << "\n";
}
ninoinui