結果
問題 | No.826 連絡網 |
ユーザー | 👑 Kazun |
提出日時 | 2021-02-10 21:09:39 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,319 bytes |
コンパイル時間 | 1,586 ms |
コンパイル使用メモリ | 86,412 KB |
実行使用メモリ | 96,812 KB |
最終ジャッジ日時 | 2023-09-22 17:03:40 |
合計ジャッジ時間 | 24,232 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
70,800 KB |
testcase_01 | AC | 73 ms
71,024 KB |
testcase_02 | AC | 84 ms
75,944 KB |
testcase_03 | AC | 111 ms
76,680 KB |
testcase_04 | AC | 119 ms
77,028 KB |
testcase_05 | AC | 103 ms
76,692 KB |
testcase_06 | AC | 107 ms
76,736 KB |
testcase_07 | AC | 114 ms
77,192 KB |
testcase_08 | AC | 108 ms
76,728 KB |
testcase_09 | AC | 112 ms
77,224 KB |
testcase_10 | AC | 94 ms
76,992 KB |
testcase_11 | AC | 111 ms
77,032 KB |
testcase_12 | AC | 1,831 ms
88,684 KB |
testcase_13 | AC | 708 ms
81,584 KB |
testcase_14 | AC | 1,466 ms
85,144 KB |
testcase_15 | AC | 212 ms
77,940 KB |
testcase_16 | AC | 924 ms
83,104 KB |
testcase_17 | AC | 707 ms
81,136 KB |
testcase_18 | AC | 540 ms
80,544 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | AC | 118 ms
77,000 KB |
testcase_22 | AC | 750 ms
81,680 KB |
testcase_23 | AC | 974 ms
82,944 KB |
testcase_24 | AC | 409 ms
79,592 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 506 ms
80,416 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 1,549 ms
86,328 KB |
testcase_29 | AC | 746 ms
81,816 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 831 ms
82,444 KB |
ソースコード
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//2+1): j=2*i while j<=N: U.union(i,j) j+=i print(U.size(P))