腾讯数分第三次笔试,(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)

#腾讯##笔试题目#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:30
仁者伍敌:kpi都懒得刷了属于是
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务