using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("3 3");
WillReturn.Add("1 2 1");
WillReturn.Add("2 3 1");
WillReturn.Add("1 3 2");
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("3 3");
WillReturn.Add("1 2 1");
WillReturn.Add("2 3 1");
WillReturn.Add("1 3 5");
//No
}
else if (InputPattern == "Input3") {
WillReturn.Add("4 3");
WillReturn.Add("2 1 1");
WillReturn.Add("2 3 5");
WillReturn.Add("3 4 2");
//Yes
}
else if (InputPattern == "Input4") {
WillReturn.Add("10 3");
WillReturn.Add("8 7 100");
WillReturn.Add("7 9 100");
WillReturn.Add("9 8 100");
//No
}
else if (InputPattern == "Input5") {
WillReturn.Add("100 0");
//Yes
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct LRInfoDef
{
internal int L;
internal int R;
internal int D;
}
struct EdgeInfoDef
{
internal int ToNode;
internal int Cost;
}
// 隣接リスト
static Dictionary<int, List<EdgeInfoDef>> mEdgeListDict =
new Dictionary<int, List<EdgeInfoDef>>();
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();
SplitAct(InputList[0]);
int N = wkArr[0];
var LRList = new List<LRInfoDef>();
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
LRInfoDef WillAdd;
WillAdd.L = wkArr[0];
WillAdd.R = wkArr[1];
WillAdd.D = wkArr[2];
LRList.Add(WillAdd);
}
foreach (LRInfoDef EachLRInfo in LRList) {
int FromNode = EachLRInfo.L;
int ToNode = EachLRInfo.R;
int Cost = EachLRInfo.D;
Action<int, int, int> AddAct = (pFromNode, pToNode, pCost) =>
{
if (mEdgeListDict.ContainsKey(pFromNode) == false) {
mEdgeListDict[pFromNode] = new List<EdgeInfoDef>();
}
EdgeInfoDef WillAdd;
WillAdd.ToNode = pToNode;
WillAdd.Cost = pCost;
mEdgeListDict[pFromNode].Add(WillAdd);
};
AddAct(FromNode, ToNode, Cost);
AddAct(ToNode, FromNode, -Cost);
}
var PosDict = new Dictionary<int, int>();
for (int I = 1; I <= N; I++) {
if (PosDict.ContainsKey(I)) {
continue;
}
if (IsValidSCC(I, PosDict) == false) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
struct JyoutaiDef
{
internal int CurrNode;
}
// 指定した引数ノードで、連結成分でDFSを行い、有効なグラフかを返す
static bool IsValidSCC(int pStaNode, Dictionary<int, int> pPosDict)
{
// 位置[人]なDict
pPosDict[pStaNode] = 1;
var Stk = new Stack<JyoutaiDef>();
JyoutaiDef WillPush;
WillPush.CurrNode = pStaNode;
Stk.Push(WillPush);
while (Stk.Count > 0) {
JyoutaiDef Popped = Stk.Pop();
int CurrNode = Popped.CurrNode;
if (mEdgeListDict.ContainsKey(CurrNode)) {
foreach (EdgeInfoDef EachEdgeInfo in mEdgeListDict[CurrNode]) {
int ToNode = EachEdgeInfo.ToNode;
// 訪問済ノードの場合は、コストに矛盾がないかを調べる
if (pPosDict.ContainsKey(ToNode)) {
int CurrCost = pPosDict[ToNode] - pPosDict[CurrNode];
if (CurrCost != EachEdgeInfo.Cost) {
return false;
}
continue;
}
// 未訪問ノードの場合
pPosDict[ToNode] = pPosDict[CurrNode] + EachEdgeInfo.Cost;
WillPush.CurrNode = ToNode;
Stk.Push(WillPush);
}
}
}
return true;
}
}