結果

問題 No.826 連絡網
ユーザー koprickykopricky
提出日時 2019-04-23 16:22:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 76,220 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-04-22 17:27:12
合計ジャッジ時間 4,944 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 22 ms
26,880 KB
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cassert>

using namespace std;

const int MAX_N = 1000005;

vector<int> G[MAX_N];
bool visit[MAX_N];
int id[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    for(int i = 2; i <= n; i++){
        G[i].assign(n / i + 20, 0);
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 2; i*j <= n; j++) {
            G[i][id[i]++] = j, G[i*j][id[i*j]++] = i;
        }
    }
    queue<int> q;
    q.push(p);
    visit[p] = true;
    int ans = 1;
    while (not q.empty()) {
        const int s = q.front();
        q.pop();
        for(int i = 0; i < id[s]; i++){
            int& to = G[s][i];
            if (visit[to]) { continue; }
            visit[to] = true;
            q.push(to);
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}
0