n,m=map(int,input().split()) primary={} for i in range(1,m+1): v,p,q=map(int,input().split()) if q==0 and i not in primary: primary[i]=[[v,p]] elif q!=0 and q not in primary: primary[q]=[[0,0]] primary[q].append([v,p] ) elif q!=0 and q in primary: ...