2022-12-26から1日間の記事一覧

Union Find のベース部分

unionfindのお約束部分 #n = int(input()) par = [-1]*n siz = [1]*n def root(x): if par[x] == -1: return x else: par[x] = root(par[x]) return par[x] def size(x): return siz[root(x)] def unite(x,y): x = root(x) y = root(y) if x == y: return Fa…

エラトステネスのふるい

エラトステネスのふるい・任意のn以下の素数のリストをO(nloglogn)(らしい)で得る。 def prime(x): x = int(x) if x < 2: return [] P = [True]*(x+1) P[0],P[1] = False,False res = [] for i in range(x+1): if P[i] == False: continue else: res.appen…