#faster ver from collections import deque N,K=map(int,input().split()) R=[] G1=[[] for _ in range(N+1)] for i in range(N): r,x=map(int,input().split()) R.append(r) G1[i].append([r,x]) G1[r].append([i,-x]) answers=[] Group_num=[-1]*(N+1) que=deque([0]) seen=[False]*(N+1) seen[0]=True B=[0]*(N+1) G2=[[] for _ in range(N+1)] while len(que): p=que.popleft() for (q,x) in G1[p]: if(not seen[q]): que.append(q) seen[q]=True B[q]=B[p]+x G2[p].append(q) for i in range(N): que=deque([0]) Group_num[0]=1 diff_L=-10**17 diff_R=10**17 ans="Yes" while len(que): p=que.popleft() for q in G2[p]: if((p==i and q==R[i]) or (q==i and p==R[i])): Group_num[q]=2 else: Group_num[q]=Group_num[p] que.append(q) seen[q]=True for j in range(N): if(Group_num[j]==Group_num[j+1]): if(B[j+1]-B[j]<0 or B[j+1]-B[j]>K): ans="No" else: if(Group_num[j]==1 and Group_num[j+1]==2): Left=B[j+1]-B[j]-K Right=B[j+1]-B[j] else: Left=B[j]-B[j+1] Right=K+B[j]-B[j+1] diff_L=max(diff_L,Left) diff_R=min(diff_R,Right) if(diff_L>diff_R): ans="No" answers.append(ans) for ans in answers: print(ans)