結果
問題 | No.826 連絡網 |
ユーザー | kurimupy |
提出日時 | 2020-06-15 15:16:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,210 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 11,212 KB |
実行使用メモリ | 8,640 KB |
最終ジャッジ日時 | 2023-09-16 10:20:02 |
合計ジャッジ時間 | 4,943 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,432 KB |
testcase_01 | AC | 16 ms
8,512 KB |
testcase_02 | AC | 17 ms
8,424 KB |
testcase_03 | AC | 46 ms
8,556 KB |
testcase_04 | AC | 60 ms
8,640 KB |
testcase_05 | AC | 30 ms
8,476 KB |
testcase_06 | AC | 31 ms
8,512 KB |
testcase_07 | AC | 53 ms
8,604 KB |
testcase_08 | AC | 32 ms
8,160 KB |
testcase_09 | AC | 58 ms
8,580 KB |
testcase_10 | AC | 23 ms
8,392 KB |
testcase_11 | AC | 43 ms
8,608 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
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)