n,m,k=map(int,input().split()) r=[-1]*(1<0: sc,s=heappop(q) if sc>v[s]: continue sp,sy=divmod(s,n) for i,ty,tc in e[sy]: if r[i]!=-1: tp=sp|(1<sc+tc: v[t]=sc+tc heappush(q,(v[t],t)) print(v[((1<