結果

問題 No.826 連絡網
ユーザー hedwig100hedwig100
提出日時 2020-04-20 14:42:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 771 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 243,456 KB
最終ジャッジ日時 2024-04-16 00:41:32
合計ジャッジ時間 25,056 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 AC 39 ms
12,032 KB
testcase_04 AC 41 ms
12,544 KB
testcase_05 AC 36 ms
11,392 KB
testcase_06 AC 35 ms
11,520 KB
testcase_07 AC 40 ms
12,288 KB
testcase_08 AC 36 ms
11,520 KB
testcase_09 AC 42 ms
12,544 KB
testcase_10 AC 33 ms
11,136 KB
testcase_11 AC 38 ms
11,904 KB
testcase_12 AC 1,842 ms
178,560 KB
testcase_13 AC 616 ms
76,928 KB
testcase_14 AC 1,355 ms
134,876 KB
testcase_15 AC 136 ms
24,832 KB
testcase_16 AC 874 ms
93,568 KB
testcase_17 AC 705 ms
76,416 KB
testcase_18 AC 522 ms
61,696 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 45 ms
13,184 KB
testcase_22 AC 692 ms
77,056 KB
testcase_23 AC 906 ms
96,768 KB
testcase_24 AC 365 ms
47,616 KB
testcase_25 TLE -
testcase_26 AC 446 ms
55,168 KB
testcase_27 AC 1,959 ms
184,576 KB
testcase_28 AC 1,478 ms
143,360 KB
testcase_29 AC 665 ms
75,776 KB
testcase_30 TLE -
testcase_31 AC 827 ms
89,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n, P = map(int,input().split())
    G = [[] for _ in range(n + 1)]
    primes = [1] * (n + 1)
    for p in range(2,n + 1):
        if primes[p]:
            for i in range(2 * p,n + 1,p):
                primes[i] = 0
                G[i].append(p)
                G[p].append(i)
    
    stack = []
    stack.append(P)
    visited = [0] * (n + 1)
    visited[P] = 1
    while stack:
        p = stack.pop()
        for v in G[p]:
            if visited[v]:
                continue
            else:
                visited[v] = 1
                stack.append(v)
    
    print(sum(visited))

if __name__ == '__main__':
    main()
0