import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IO
import Control.Monad

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  info <- sort . map (\[x,y,z] -> (x,y,z)) <$> getInt2DListBC
  weight <- newArray (1, n) 0 :: IO Arr
  parent <- newListArray (1, n) [1..n] :: IO Arr
  ans <- unionFind weight parent info
  if ans
    then putStrLn "Yes"
    else putStrLn "No"

type EdgeW = (Int, Int, Int)
type Arr = IOUArray Int Int
type Used = IOUArray Int Bool

unionFind :: Arr -> Arr -> [EdgeW] -> IO Bool
unionFind weight parent [] = return True
unionFind weight parent ((i, j, w):es) = do
  (pI, wI) <- getRepresentative parent weight i
  (pJ, wJ) <- getRepresentative parent weight j
  if pI == pJ
    then do
      if wI + w == wJ
        then unionFind weight parent es
        else return False
    else do
      if wI > 0 && wJ > 0 || pI == i && pJ == j
        then do
          if wI + w > wJ
            then do
              writeArray parent pJ pI
              writeArray weight pJ $ wI + w - wJ
              unionFind weight parent es
            else do
              writeArray parent pI pJ
              writeArray weight pI $ wJ - w - wI
              unionFind weight parent es
        else do
          if wI > 0
            then do
              writeArray parent pJ pI
              writeArray weight pJ $ w + wI
              unionFind weight parent es
            else do
              writeArray parent pI pJ
              writeArray weight pI $ w + wJ
              unionFind weight parent es

getRepresentative :: Arr -> Arr -> Int -> IO (Int, Int)
getRepresentative parent weight i = do
  p <- readArray parent i
  w <- readArray weight i
  if i == p
    then do
      return (i, w)
    else do
      (pp, ww) <- getRepresentative parent weight p
      writeArray parent i pp
      writeArray weight i $ w + ww
      return (pp, w+ww)

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getInt2DListBC :: IO [[Int]]
getInt2DListBC = map (map bsToInt . BC.words) . BC.lines <$> BC.getContents
