n, m = map(int,input().split()) primary, annex = {}, {} for i in range(1,m+1): x, y, z = map(int, input().split()) if z==0: primary[i] = [x, y] else: if z in annex: annex[z].append([x, y]) else: annex[z] = [[x,y]] dp = [0]*(n+1) for key in ...