結果
| 問題 |
No.826 連絡網
|
| コンテスト | |
| ユーザー |
treeone
|
| 提出日時 | 2019-05-03 21:29:32 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 991 bytes |
| コンパイル時間 | 7,656 ms |
| コンパイル使用メモリ | 257,296 KB |
| 最終ジャッジ日時 | 2025-01-07 03:21:00 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | RE * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:17: warning: 'j' may be used uninitialized [-Wmaybe-uninitialized]
39 | for(int j = 2 * j; j <= n; j += i){
| ^
main.cpp:39:17: note: 'j' was declared here
39 | for(int j = 2 * j; j <= n; j += i){
| ^
ソースコード
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;
struct UF{
vector<int> par, sz;
UF(){}
UF(int n):par(n), sz(n, 1){
iota(par.begin(), par.end(), 0);
}
int find(int x){
if(x == par[x]) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y){
x = find(x); y = find(y);
if(x == y) return;
if(sz[x] < sz[y]) swap(x, y);
sz[x] += sz[y];
par[y] = x;
}
bool same(int x, int y){
return find(x) == find(y);
}
};
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, p;
cin >> n >> p;
UF uf(n + 1);
for(int i = 2; i <= n; i++){
if(uf.find(i) != i) continue;
for(int j = 2 * j; j <= n; j += i){
uf.unite(i, j);
}
}
cout << uf.sz[uf.find(p)] << endl;
}
treeone