uu帮忙看看最后一题, from collections import defaultdict nodes = defaultdict(list) n, a, b, m = map(int, input().split()) roots = list(map(int, input().split())) for i, x in enumerate(roots): nodes[x].append(i+2) def dfs(i): if len(nodes[i]) == 0: return 0 t = 0 for nx in nodes[i]: t += (dfs(nx) % m + a**i % m) * b % m return t % m print(dfs(1))
点赞 5

相关推荐

09-01 09:00
已编辑
四川旅游学院 运营
牛客55195891...:主要是专业不好,别的没毛病
牛客解忧铺
点赞 评论 收藏
分享
AC鸽想进大厂:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务