結果
問題 | No.826 連絡網 |
ユーザー | kurimupy |
提出日時 | 2020-06-15 15:16:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 245 ms / 2,000 ms |
コード長 | 2,210 bytes |
コンパイル時間 | 269 ms |
コンパイル使用メモリ | 82,604 KB |
実行使用メモリ | 83,840 KB |
最終ジャッジ日時 | 2024-07-03 11:24:44 |
合計ジャッジ時間 | 4,716 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,480 KB |
testcase_02 | AC | 53 ms
61,568 KB |
testcase_03 | AC | 66 ms
69,632 KB |
testcase_04 | AC | 67 ms
69,888 KB |
testcase_05 | AC | 79 ms
68,864 KB |
testcase_06 | AC | 76 ms
69,120 KB |
testcase_07 | AC | 67 ms
69,888 KB |
testcase_08 | AC | 61 ms
69,632 KB |
testcase_09 | AC | 65 ms
69,504 KB |
testcase_10 | AC | 53 ms
64,512 KB |
testcase_11 | AC | 64 ms
69,632 KB |
testcase_12 | AC | 188 ms
81,664 KB |
testcase_13 | AC | 109 ms
78,080 KB |
testcase_14 | AC | 151 ms
80,108 KB |
testcase_15 | AC | 71 ms
73,088 KB |
testcase_16 | AC | 123 ms
78,720 KB |
testcase_17 | AC | 111 ms
78,208 KB |
testcase_18 | AC | 102 ms
77,968 KB |
testcase_19 | AC | 213 ms
82,688 KB |
testcase_20 | AC | 208 ms
82,432 KB |
testcase_21 | AC | 66 ms
69,888 KB |
testcase_22 | AC | 111 ms
78,236 KB |
testcase_23 | AC | 123 ms
78,592 KB |
testcase_24 | AC | 92 ms
77,300 KB |
testcase_25 | AC | 240 ms
83,584 KB |
testcase_26 | AC | 94 ms
77,312 KB |
testcase_27 | AC | 198 ms
81,664 KB |
testcase_28 | AC | 158 ms
80,436 KB |
testcase_29 | AC | 109 ms
78,040 KB |
testcase_30 | AC | 245 ms
83,840 KB |
testcase_31 | AC | 119 ms
78,716 KB |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * (n+1) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n + 1) 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): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) class UnionFindLabel(UnionFind): def __init__(self, labels): assert len(labels) == len(set(labels)) self.n = len(labels) self.parents = [-1] * self.n self.d = {x: i for i, x in enumerate(labels)} self.d_inv = {i: x for i, x in enumerate(labels)} def find_label(self, x): return self.d_inv[super().find(self.d[x])] def union(self, x, y): super().union(self.d[x], self.d[y]) def size(self, x): return super().size(self.d[x]) def same(self, x, y): return super().same(self.d[x], self.d[y]) def members(self, x): root = self.find(self.d[x]) return [self.d_inv[i] for i in range(self.n+1) if self.find(i) == root] def roots(self): return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0] ################################ N, P = map(int, input().split()) Uni = UnionFind(N) for i in range(2, N): for j in range(2, N): if j*i > N: break Uni.union(i, i*j) ans = Uni.size(P) print(ans)