using namespace std;
struct node
{
int a;
int b;
int c;
};
int f[100010];
node h[100010];
int j[100];
int n,m;
bool cmp1(node x,node y)
{
return x.c<y.c;
}
bool cmp2(node x,node y)
{
return x.c>y.c;
}
int father(int x)
{
return f[x]==x?x:f[x]=father(f[x]);
}
int k()
{
int cnt=0;
int op=0;
for(int i=0;i<=m;i++) f[i]=i;
for(int i=0;i<m && op<n-1;i++)
{
int fa=father(h[i].a);
int fb=father(h[i].b);
if(fa!=fb)
{
op++;
cnt+=h[i].c;
f[h[i].a]=h[i].b;
}
}
}
int main()
{
j[1]=1,j[2]=2;
for(int i=3;i<=60;i++)
{
j[i]=j[i-1]+j[i-2];
}
while(scanf("%d%d",&n,&m)==2)
{
for(int i=0;i<m;i++)
{
cin>>h[i].a>>h[i].b>>h[i].c;
h[i].c=(h[i].c+1)%2;
}
//cout<<1;
sort(h,h+m,cmp1);
int mx=k();
sort(h,h+m,cmp2);
int mn=k();
int u=0;
for(int i=1;i<=60;i++)
{
if(mn<=j[i] && mx>=j[i])
{
u=1;
break;
}
}
if(!u) printf("No\n");
else printf("Yes\n");
}
}
hhhhelp