2
def getCoprimes(self, nums: List[int], edges: List[List[int]]) -> List[int]:4
gcdset = [set() for i in range(51)]7
if math.gcd(i, j) == 1:11
graph = defaultdict(list)16
ans = [-1] * len(nums)22
for node, ancestors in q:23
index_depth = (-1, -1)24
for anc in list(ancestors.keys()):25
if anc in gcdset[nums[node]]:26
index, d = ancestors[anc]27
if d > index_depth[1]:28
index_depth = (index, d)29
ans[node] = index_depth[0]31
copy = ancestors.copy()32
copy[nums[node]] = (node, depth)34
for child in graph[node]:37
temp.append([child, copy])