結果
問題 | No.826 連絡網 |
ユーザー | convexineq |
提出日時 | 2021-04-03 12:47:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 622 ms / 2,000 ms |
コード長 | 1,148 bytes |
コンパイル時間 | 1,561 ms |
コンパイル使用メモリ | 86,384 KB |
実行使用メモリ | 92,884 KB |
最終ジャッジ日時 | 2023-08-26 02:44:48 |
合計ジャッジ時間 | 10,733 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,288 KB |
testcase_01 | AC | 73 ms
71,140 KB |
testcase_02 | AC | 80 ms
75,516 KB |
testcase_03 | AC | 106 ms
77,144 KB |
testcase_04 | AC | 105 ms
77,360 KB |
testcase_05 | AC | 100 ms
77,404 KB |
testcase_06 | AC | 102 ms
77,228 KB |
testcase_07 | AC | 103 ms
77,392 KB |
testcase_08 | AC | 100 ms
77,432 KB |
testcase_09 | AC | 106 ms
77,180 KB |
testcase_10 | AC | 89 ms
76,240 KB |
testcase_11 | AC | 102 ms
77,352 KB |
testcase_12 | AC | 473 ms
88,432 KB |
testcase_13 | AC | 241 ms
81,752 KB |
testcase_14 | AC | 386 ms
85,708 KB |
testcase_15 | AC | 133 ms
78,160 KB |
testcase_16 | AC | 272 ms
82,788 KB |
testcase_17 | AC | 248 ms
81,764 KB |
testcase_18 | AC | 213 ms
80,676 KB |
testcase_19 | AC | 530 ms
90,456 KB |
testcase_20 | AC | 529 ms
90,104 KB |
testcase_21 | AC | 109 ms
77,508 KB |
testcase_22 | AC | 252 ms
81,884 KB |
testcase_23 | AC | 300 ms
83,008 KB |
testcase_24 | AC | 182 ms
79,892 KB |
testcase_25 | AC | 615 ms
92,884 KB |
testcase_26 | AC | 199 ms
80,172 KB |
testcase_27 | AC | 469 ms
88,796 KB |
testcase_28 | AC | 381 ms
86,404 KB |
testcase_29 | AC | 235 ms
81,800 KB |
testcase_30 | AC | 622 ms
92,772 KB |
testcase_31 | AC | 271 ms
82,556 KB |
ソースコード
class UnionFind: def __init__(self, n): self.parent = list(range(n)) #親ノード self.size = [1]*n #グループの要素数 def root(self, x): #root(x): xの根ノードを返す. while self.parent[x] != x: self.parent[x] = self.parent[self.parent[x]] x = self.parent[x] return x def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる x, y = self.root(x), self.root(y) if x == y: return False if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように self.size[x] += self.size[y] #xの要素数を更新 self.parent[y] = x #yをxにつなぐ return True def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue return self.root(x) == self.root(y) def getsize(self,x): #size(x): xのいるグループの要素数を返す return self.size[self.root(x)] n,p = map(int,input().split()) UF = UnionFind(n+1) for i in range(2,n+1): if UF.getsize(i) > 1: continue for j in range(2*i,n+1,i): UF.merge(i,j) print(UF.getsize(p))