#include <iostream>
#include <vector>
using namespace std;
bool bt(int i,vector<pair<int,int>> pos,int l,int r,int k,vector<int>& posl,vector<int>& posr,vector<int>& s){
if(i==pos.size()&&abs(l-r)<=k)return true;
else if(i==pos.size())return false;
if(posl[pos[i].first]){
posl[pos[i].first]=0;
l+=s[i];
if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
posl[pos[i].first]=1;
l-=s[i];
}
if(posr[pos[i].second]){
posr[pos[i].second]=0;
r+=s[i];
if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
posr[pos[i].second]=1;
r-=s[i];
}
return false;
}
int main(){
int n,k;
cin>>n>>k;
vector<pair<int,int>> pos(2*n);
vector<int> posl(n,1),posr(n,1),s(2*n);
for(int i=0;i<2*n;i++)cin>>pos[i].first>>pos[i].second>>s[i];
for(int i=0;i<2*n;i++){
pos[i].first--;pos[i].second--;
}
if(bt(0,pos,0,0,k,posl,posr,s))cout<<"YES\n";
else cout<<"NO\n";
}