結果

問題 No.826 連絡網
ユーザー rlangevinrlangevin
提出日時 2023-02-08 08:54:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 874 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 456,740 KB
最終ジャッジ日時 2023-09-20 02:32:01
合計ジャッジ時間 7,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,064 KB
testcase_01 AC 92 ms
71,472 KB
testcase_02 AC 107 ms
77,528 KB
testcase_03 AC 120 ms
77,948 KB
testcase_04 AC 125 ms
78,060 KB
testcase_05 AC 115 ms
77,956 KB
testcase_06 AC 116 ms
78,028 KB
testcase_07 AC 124 ms
78,124 KB
testcase_08 AC 117 ms
77,964 KB
testcase_09 AC 125 ms
78,016 KB
testcase_10 AC 114 ms
77,900 KB
testcase_11 AC 121 ms
77,704 KB
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 #

from collections import deque

def bfs(G, s, N):
    Q = deque([])
    dist = [-1] * N
    par = [-1] * N
    sz = [1] * N
    dist[s] = 0
    rev = [0] * N
    for u in G[s]:
        par[u] = s
        dist[u] = 1
        sz[u] += sz[s]
        Q.append(u)
 
    while Q:
        u = Q.popleft()
        for v in G[u]:
            if dist[v] != -1:
                continue
            if v < u:
                rev[v] = rev[u] + 1
            else:
                rev[v] = rev[u]
            dist[v] = dist[u] + 1
            par[v] = u
            sz[v] += sz[u]
            Q.append(v)
            
    return dist


N, P = map(int, input().split())
G = [[] for i in range(N + 1)]
for i in range(2, N):
    for j in range(i, N + 1, i):
        if j + i <= N:
            G[j].append(j + i)
            G[j + i].append(j)

D = bfs(G, P, N + 1)
print(N + 1 - D.count(-1))
0