腾讯数分第三次笔试,(5)示例全对测试全错有大佬帮我看一眼吗
class treenode: def __init__(self,val,num): self.num = num self.child = [] self.val = val n = int(input()) a = list(map(int,input().split(' '))) root = treenode(a[0],1) beifen = root fa = list(map(int,input().split(' '))) for i in range(1,len(a)): index = 0 out = False while 1: if root.num == fa[i-1]: child = treenode(a[i],i+1) root.child.append(child) root = beifen break else: root = root.child[index] index += 1 continue root = beifen count = 0 que = [] que.append(root) while que: father = que.pop(0) s = [] res = [] if father.child: for item in father.child: s.append(item) res.append(item) que.append(item) while s: a = s.pop() if a.child: for item in a.child: res.append(item) s.append(item) else: continue for item in res: if (pow(father.val * item.val,0.5) * 10) % 10 == 0: count += 1 else: continue print(count)
#腾讯##笔试题目#