import sys input = sys.stdin.readline from heapq import heappop,heappush N,M,C=map(int,input().split()) E=[[] for i in range(N)] for i in range(M): a,b,c=map(int,input().split()) a-=1 b-=1 E[a].append((b,c)) E[b].append((a,c)) D=[1<<63]*N D[0]=0 Q=[(0,0)] while Q: dis,ind=heappop(Q) if D[ind]!=dis: continue for to,length in E[ind]: if D[to]>D[ind]+length+C: D[to]=D[ind]+length+C heappush(Q,(D[to],to)) ANS=[D[-1]]*N D2=[(1<<63,0)]*N D2[N-1]=(0,0) Q=[((0,0),N-1)] while Q: (dis,m),ind=heappop(Q) if D2[ind]!=(dis,m): continue for to,length in E[ind]: m2=max(m,length) dis2=dis+m+length-m2+C if D2[to]>(dis2,m2): D2[to]=(dis2,m2) heappush(Q,(D2[to],to)) for i in range(1,N): x=D2[i][0] ANS[i]=min(ANS[i],x+D[i]) print("\n".join(map(str,ANS[1:])))