結果
問題 | No.826 連絡網 |
ユーザー | kurimupy |
提出日時 | 2020-06-15 15:16:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 265 ms / 2,000 ms |
コード長 | 2,210 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 87,220 KB |
実行使用メモリ | 84,968 KB |
最終ジャッジ日時 | 2023-09-16 10:21:02 |
合計ジャッジ時間 | 5,798 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,384 KB |
testcase_01 | AC | 70 ms
71,552 KB |
testcase_02 | AC | 78 ms
76,104 KB |
testcase_03 | AC | 92 ms
76,500 KB |
testcase_04 | AC | 92 ms
76,724 KB |
testcase_05 | AC | 89 ms
76,860 KB |
testcase_06 | AC | 93 ms
76,676 KB |
testcase_07 | AC | 94 ms
76,352 KB |
testcase_08 | AC | 91 ms
76,716 KB |
testcase_09 | AC | 94 ms
76,612 KB |
testcase_10 | AC | 83 ms
76,680 KB |
testcase_11 | AC | 93 ms
76,528 KB |
testcase_12 | AC | 208 ms
82,892 KB |
testcase_13 | AC | 134 ms
79,472 KB |
testcase_14 | AC | 174 ms
81,228 KB |
testcase_15 | AC | 100 ms
77,848 KB |
testcase_16 | AC | 147 ms
80,116 KB |
testcase_17 | AC | 136 ms
79,516 KB |
testcase_18 | AC | 125 ms
79,084 KB |
testcase_19 | AC | 237 ms
83,764 KB |
testcase_20 | AC | 234 ms
83,596 KB |
testcase_21 | AC | 94 ms
76,904 KB |
testcase_22 | AC | 135 ms
79,412 KB |
testcase_23 | AC | 148 ms
80,328 KB |
testcase_24 | AC | 116 ms
78,320 KB |
testcase_25 | AC | 265 ms
84,968 KB |
testcase_26 | AC | 120 ms
78,828 KB |
testcase_27 | AC | 214 ms
82,892 KB |
testcase_28 | AC | 179 ms
81,540 KB |
testcase_29 | AC | 133 ms
79,280 KB |
testcase_30 | AC | 263 ms
84,928 KB |
testcase_31 | AC | 142 ms
79,988 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)