using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_D.MyIO;



public class Contest_D
{
	static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
	static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); }  // b の方が小さければ交換
	static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; }  // b の方が小さければ a を更新
	static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; }  // b の方が大きければ a を更新
	static bool inside(long i, long n) => (0<=i&&i<n);
	static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
	static T min<T>(params T[] a) where T : IComparable => a.Min();
	static T max<T>(params T[] a) where T : IComparable => a.Max();
	static long mod(long a, long m) { var v = a%m; return (v<0?v+m:v); }
	static T[][] init<T>(long len1,long len2,T val) where T : struct { T[][] m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
	static T[][][] init<T>(long len1,long len2,long len3,T val) where T : struct { T[][][] m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = init(len2,len3,val); return m; }
	public const long MOD1 = 1000000007; // 10^9+7
	public const double EPS1 = 1e-8;
	public const long INF1 = 1000000000000000;  // 10^15

	public static void Main() {
		checked{
			long  n, m;
			MyIO.RM(out n, out m);
			VT<ll,ll,ll>[] lrdl;
			RL(m,out lrdl);


			if(m<2){
				WM("Yes");
				return;
			}

			UnionFind uf = new UnionFind(n);
			foreach (var e in lrdl)
			{
				uf.Unite(e.Item1-1,e.Item2-1);
			}

			var g = MakeGraph(lrdl,n,-1);
			foreach (var e in uf.AllSizes())
			{
				if(!Search(1,n,g,e.Key,null)){
					WM("No");
					return;
				}
			}

			MyIO.WM("Yes");
		}
	}

    public static List<VT<long,long>>[] MakeGraph(VT<long,long,long>[] inEdges, long N=-1, long shift=0){
		if(N==-1){
			foreach (var e in inEdges)
			{
				if(N<e.Item1) N = e.Item1;
				if(N<e.Item2) N = e.Item2;
			}
			N += shift+1;
		}
        List<VT<long,long>>[] ret = new List<VT<long,long>>[Math.Max(N,0)];
        if (ret.Length==0) return ret;
        for (int i = 0; i < ret.Length; i++) ret[i] = new List<VT<long,long>>();
		foreach (var e in inEdges)
        {
            ret[e.Item1+shift].Add(new VT<long, long>(e.Item2+shift,e.Item3));
            ret[e.Item2+shift].Add(new VT<long, long>(e.Item1+shift,-e.Item3));
        }
        return ret;
    }
    public static bool Search(long stype, long N, IList<IList<VT<ll,ll>>> graph, long startidx, object startinfo){
        var que = new ModQue<VT<long,VT<ll,ll>>>(stype);
        que.In(new VT<long, VT<ll,ll>>(startidx,new VT<ll,ll>(-1,0)));  // 第２引数は次のノードに渡す情報を代入（コストの和など）
        bool[] visited = new bool[N]; 
		ll[] cood = Enumerable.Repeat(ll.MaxValue,(int)N).ToArray();
        while(0<que.Count()){
            var cur = que.Out();
			var info = cur.Item2;
			if(info.Item1!=-1&&cood[cur.Item1]!=ll.MaxValue&&cood[cur.Item1]!=info.Item2+cood[info.Item1]) return false;
            if(visited[cur.Item1]) continue;
            visited[cur.Item1]=true;
			if(cood[cur.Item1]==ll.MaxValue){
				cood[cur.Item1]=info.Item2+((info.Item1==-1)?0:cood[info.Item1]);
			}
            foreach (var e in graph[(int)cur.Item1]) {
                que.In(new VT<long, VT<ll,ll>>(e.Item1,new VT<ll,ll>(cur.Item1,e.Item2)));
            }
        }
		return true;
    }
	public class ModQue<T>{
		readonly public Action Clear;
		readonly public Action<T> In;
		readonly public Func<T> Out, Peek;
		readonly public Func<int> Count;
		public ModQue(long type){
			if(type==1) {
				var S = new Stack<T>();
				Clear = S.Clear; Peek = S.Peek; Count = () => S.Count; In = S.Push; Out = S.Pop;
			}
			if(type==2) {
				var Q = new Queue<T>();
				Clear = Q.Clear; Peek = Q.Peek; Count = () => Q.Count; In = Q.Enqueue; Out = Q.Dequeue;
			}
		}
	}
public class UnionFind {
    private long[] data;

    public UnionFind(long size) {
        data = new long[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(long x, long y) {
        x = Find(x);
        y = Find(y);

        if (x != y) {
            if (data[y] < data[x]) { var t = y; y = x; x = t; }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(long x, long y) { return Find(x) == Find(y); }
    public long Find(long x) { return data[x] < 0 ? x : data[x] = Find(data[x]); }
    public long Size(long x) { return -data[Find(x)]; }
	public Dictionary<long,long> AllSizes(){
		Dictionary<long,long> ret = new Dictionary<long, long>();
		for (int i = 0; i < data.Length; i++)  if(data[i]<0) ret[i] = -data[i];
		return ret;
	}
}



#region MyIO

public struct VT<T,U>
{
	public T Item1; public U Item2;
    public VT(T a,U b) { Item1 = a; Item2 = b; }
}
public struct VT<T,U,V>
{
	public T Item1; public U Item2; public V Item3;
    public VT(T a,U b,V c) { Item1 = a; Item2 = b; Item3 = c; }
}
public struct VT<T,U,V,W>
{
	public T Item1; public U Item2; public V Item3; public W Item4;
    public VT(T a,U b,V c,W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; }
}

public static class MyIO
{
	class Prt : System.IO.StreamWriter
	{
		public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
		public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
		public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
	}
	
	static char[] sp = new char[] {' '};
	[MethodImpl(256)]
	static bool eq<T,U>() => typeof(T).Equals(typeof(U));
	[MethodImpl(256)]
	static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
	static T cv<T>(string s) =>
		eq<T,int>()    ? ct<T,int>(int.Parse(s))
	  : eq<T,long>()   ? ct<T,long>(long.Parse(s))
	  : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
	  : eq<T,char>()   ? ct<T,char>(s[0])
					   : ct<T,string>(s);
	public static string[] RM<T>(out T a) {
		var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(z[0]);
		return z;
	}
	public static string[] RM<T,U>(out T a,out U b) {
		var z = RM<T>(out a); 
        b = cv<U>(z[1]);
		return z;
	}
	public static string[] RM<T,U,V>(out T a,out U b,out V c) {
		var z = RM<T,U>(out a,out b); 
        c = cv<V>(z[2]);
		return z;
	}
	public static string[] RM<T,U,V,W>(out T a,out U b,out V c,out W d) {
		var z = RM<T,U,V>(out a,out b,out c); 
        d = cv<W>(z[3]);
		return z;
	}
	public static string[] RM<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
		var z = RM<T,U,V,W>(out a,out b,out c,out d); 
        e = cv<X>(z[4]);
		return z;
	}
	public static string[] RM<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) {
		var z = RM<T,U,V,W,X>(out a,out b,out c,out d,out e); 
        f = cv<Y>(z[5]);
		return z;
	}
	public static string[] RA<T>(out T[] a) {		
		var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
		a = z.Select(cv<T>).ToArray();
		return z;
	}
	public static string[][] RL<T>(long n,out T[] a) {
		a = new T[n];
		var y = new string[n][];
		for(int i=0;i<n;i++) y[i] = RM(out a[i]);
		return y;
	}
	public static string[][] RL<T,U>(long n,out VT<T,U>[] a) {
		a = new VT<T,U>[n];
		var y = new string[n][];
		for(int i=0;i<n;i++) {
			T o; U p;
			y[i] = RM(out o,out p);
			a[i] = new VT<T,U>(o,p);
		}
		return y;
	}
	public static string[][] RL<T,U,V>(long n,out VT<T,U,V>[] a) {
		a = new VT<T,U,V>[n];
		var y = new string[n][];
		for(int i=0;i<n;i++) {
			T o; U p; V q;
			y[i] = RM(out o,out p,out q);
			a[i] = new VT<T,U,V>(o,p,q);
		}
		return y;
	}
	public static string[][] RL<T,U,V,W>(long n,out VT<T,U,V,W>[] a) {
		a = new VT<T,U,V,W>[n];
		var y = new string[n][];
		for(int i=0;i<n;i++) {
			T o; U p; V q; W r;
			y[i] = RM(out o,out p,out q,out r);
			a[i] = new VT<T,U,V,W>(o,p,q,r);
		}
		return y;
	}
	public static string[][] RX<T>(long n,out T[][] a) {
		a = new T[n][];
		var y = new string[n][];
		for(int i=0;i<n;i++) y[i] = RA(out a[i]);
		return y;
	}

	static void wwp(Action act){
		var s = new Prt(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(s);
		act();
		Console.Out.Flush();
		s.AutoFlush = true;
		Console.SetOut(s);
	}
	[MethodImpl(256)]
	static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
	public static void WM(params object[] a) {
		wwp(()=>{
			for(int i=0;i<a.Length;i++) {
				var f = wfm(a[i].GetType()) + ((i<a.Length-1) ? " " : Environment.NewLine);
				Console.Write(f,a[i]);
			}
		});
	}
	public static void WA<T>(IList<T> a) {
		wwp(()=>{
			var f = wfm(typeof(T));
			var g = f + " ";
			var h = f + Environment.NewLine;
			for(int i=0;i<a.Count;i++) Console.Write(((i<a.Count-1) ? g : h),a[i]);
		});
	}
	public static void WL<T>(IList<T> a) {
		wwp(()=>{
			var f = wfm(typeof(T)) + Environment.NewLine;
			foreach(T x in a) Console.Write(f,x);
		});
	}


}

#endregion


}

