#include<bits/stdc++.h>
using namespace std;
struct team { int l,r,v; };
struct edge { int pe,nex,val; };
const int MAXN=6e4+36;
bitset<MAXN*20> bt;
team A[MAXN];
vector<edge> ds[MAXN];
bool ck[MAXN];
int fx=0,fy=0;
void dfs(int i,int pre,int n)
{
ck[i]=true;
for(auto v:ds[i]) if(v.pe!=pre)
{
if(i<=n) fx+=v.val;
else fy+=v.val;
if(!ck[v.nex]) dfs(v.nex,v.pe,n);
break;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k,sum=0;
cin>>n>>k;
for(int i=1;i<=n*2;i++)
{
int x,y,v;
cin>>x>>y>>v;
ds[x].push_back({i,y+n,v}),ds[y+n].push_back({i,x,v}),sum+=v;
}
for(int i=1;i<=n*2;i++) if(ds[i].size()!=2) return cout<<"NO",0;
bt[0]=1;
int cnt=0;
for(int i=1;i<=n*2;i++) if(!ck[i])
{
fx=fy=0;
dfs(i,0,n);
bt=(bt<<fx)|(bt<<fy);
}
bool ck=false;
for(int i=0;i<=sum;i++) if(abs(sum-i*2)<=k) ck|=bt[i];
if(ck) cout<<"YES";
else cout<<"NO";
}