def main(): n, m, B = list(map(int, input().split())) node = [[] for _ in range(n)] node_ = [[] for _ in range(n)] for _ in range(m): u, v, c = list(map(int, input().split())) node[u-1].append((v-1, c)) node[v-1].append((u-1, c)) node_[u-1].append((v-1, c)) node_[v-1].append((u-1, c)) Ans = [-1] * n for s in range(n): if Ans[s] != -1: continue D = {s: 0} S = [(s, 0)] X = [] while S: now = S[-1][0] if not node_[now]: S.pop() else: nxt, c = node_[now].pop() if not nxt in D: D[nxt] = D[now]^1 S.append((nxt, c)) elif D[nxt] == D[now]: X = [(nxt, c)] while S[-1][0] != nxt: X.append(S.pop()) break if X: s0 = X[0][0] d_sum = 0 for _, c in X[1::2]: d_sum += c d_sum %= B c_sum = sum([c for _, c in X]) % B if B % 2: c_s0s = [(c_sum * pow(2, -1, B)-d_sum) % B] elif c_sum % 2: return [] else: c_s0s = [(c_sum-d_sum)%B, ((c_sum+B)//2-d_sum)%B] for c_s0 in c_s0s: D = {s0: c_s0} S = [s0] f = 1 while S and f: now = S.pop() for nxt, c in node[now]: if nxt in D: if (D[nxt]+D[now]) % B != c: f = 0 break else: D[nxt] = (c-D[now]) % B S.append(nxt) if f: for now in D: Ans[now] = D[now] break else: return [] else: Ans[s] = 0 S = [s] while S: now = S.pop() for nxt, c in node[now]: if Ans[nxt] != -1: if (Ans[nxt]+Ans[now]) % B != c: return [] else: Ans[nxt] = (c-Ans[now]) % B S.append(nxt) return Ans Ans = main() if Ans: print("Yes") print(*Ans) else: print("No")