結果

問題 No.826 連絡網
ユーザー 👑 KazunKazun
提出日時 2021-02-10 21:07:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,314 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 86,600 KB
実行使用メモリ 93,168 KB
最終ジャッジ日時 2023-09-22 17:02:11
合計ジャッジ時間 29,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,564 KB
testcase_01 AC 73 ms
71,324 KB
testcase_02 AC 84 ms
76,380 KB
testcase_03 AC 111 ms
77,192 KB
testcase_04 AC 117 ms
77,336 KB
testcase_05 AC 104 ms
77,136 KB
testcase_06 AC 106 ms
77,436 KB
testcase_07 AC 116 ms
77,096 KB
testcase_08 AC 108 ms
76,976 KB
testcase_09 AC 116 ms
77,052 KB
testcase_10 AC 93 ms
76,784 KB
testcase_11 AC 113 ms
77,276 KB
testcase_12 AC 1,898 ms
88,532 KB
testcase_13 AC 713 ms
81,804 KB
testcase_14 AC 1,486 ms
85,708 KB
testcase_15 AC 231 ms
77,972 KB
testcase_16 AC 924 ms
82,984 KB
testcase_17 AC 749 ms
81,576 KB
testcase_18 AC 563 ms
80,664 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 124 ms
77,568 KB
testcase_22 AC 752 ms
81,752 KB
testcase_23 AC 976 ms
83,084 KB
testcase_24 AC 476 ms
80,128 KB
testcase_25 TLE -
testcase_26 AC 533 ms
80,080 KB
testcase_27 TLE -
testcase_28 AC 1,595 ms
86,184 KB
testcase_29 AC 790 ms
81,412 KB
testcase_30 TLE -
testcase_31 AC 805 ms
82,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        N:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        V=[]
        while self.parents[x]>=0:
            V.append(x)
            x=self.parents[x]

        for v in V:
            self.parents[v]=x
        return x

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return

        if self.rank[x]<self.rank[y]:
            x,y=y,x

        self.parents[x]+=self.parents[y]
        self.parents[y]=x

        if self.rank[x]==self.rank[y]:
            self.rank[x]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        X={r:[] for r in self.roots()}
        for k in range(self.n):
            X[self.find(k)].append(k)
        return X

    def refresh(self):
        for i in range(self.n):
            _=self.find(i)

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def __repr__(self):
        return self.__str__()
#================================================
N,P=map(int,input().split())
U=Union_Find(N+1)
for i in range(2,N):
    j=2*i
    while j<=N:
        U.union(i,j)
        j+=i

print(U.size(P))
0