All, num = map(int, input().split()) pri, attach ={}, {} # 现在要计算主件和附件,并纳入字典中,这部分是input的 for i in range(1, num+1): [v, p, q] = map(int, input().split()) if q == 0: # 只有主件 pri[i] = [v, p] else: if q in attach: attach[q].append([v, p]) #存在2个附件 ...