import sys input = sys.stdin.readline N,M,mod=list(map(int,input().split())) E=[[] for i in range(N)] for i in range(M): x,y,c=list(map(int,input().split())) x-=1 y-=1 E[x].append((y,c)) E[y].append((x,c)) ANS=[-1]*N for i in range(N): if ANS[i]!=-1: continue else: for j in range(mod): Q=[i] ANS[i]=j LIST=[] flag=1 while Q: #print(Q,ANS,LIST) x=Q.pop() LIST.append(x) for to,c in E[x]: tov=(c-ANS[x])%mod if ANS[to]==-1: ANS[to]=tov Q.append(to) else: if ANS[to]!=tov: flag=0 break #print(LIST) if flag: break else: for xx in LIST: ANS[xx]=-1 else: print("No") exit() print("Yes") print(*ANS)