Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    rmvlist=[]
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif r in x and l not in x:
            x[l] = x[r] -d
            rmvlist.append(i)
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                rmvlist.append(i)
    if len(rmvlist)==0:
        x[LRD[0][0]]=0
    else:
        LRD=[LRD[i]for i in range(len(LRD)) if i not in rmvlist]

print("Yes No".split()[1-flag])

Fixed submission:
import queue,sys
# 解説読んだ後
N,M=map(int,input().split())
# networkを作る
G={}
LRD=[]
for i in range(1,N+1):
    G[i]={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
    G[l][r]=d
    G[r][l]=-d
if M==0:
    print("Yes")
    sys.exit()
notvisit=set(range(1,N+1))
Q=queue.Queue()
x={}
while notvisit:
    current=notvisit.pop()
    Q.put(current)
    x[current]=0
    while Q.qsize():
        nex=Q.get()
        for k,v in G[nex].items():
            if k in x:
                if x[k]!= x[nex]+G[nex][k]:
                    print("No")
                    sys.exit()
            else:
                x[k]=x[nex]+G[nex][k]
                Q.put(k)
                notvisit.remove(k)
print("Yes")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    rmvlist=[]
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif r in x and l not in x:
            x[r] = x[l] +d
            rmvlist.append(i)
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                rmvlist.append(i)
    if len(rmvlist)==0:
        x[LRD[0][0]]=0
    else:
        LRD=[LRD[i]for i in range(len(LRD)) if i not in rmvlist]

print("Yes No".split()[1-flag])

Fixed submission:
import queue,sys
# 解説読んだ後
N,M=map(int,input().split())
# networkを作る
G={}
LRD=[]
for i in range(1,N+1):
    G[i]={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
    G[l][r]=d
    G[r][l]=-d
if M==0:
    print("Yes")
    sys.exit()
notvisit=set(range(1,N+1))
Q=queue.Queue()
x={}
while notvisit:
    current=notvisit.pop()
    Q.put(current)
    x[current]=0
    while Q.qsize():
        nex=Q.get()
        for k,v in G[nex].items():
            if k in x:
                if x[k]!= x[nex]+G[nex][k]:
                    print("No")
                    sys.exit()
            else:
                x[k]=x[nex]+G[nex][k]
                Q.put(k)
                notvisit.remove(k)
print("Yes")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
LRD=[]
x={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
if LRD:
    x[LRD[0][0]]=0
flag=True
while LRD and flag:
    ct=len(LRD)
    for i in range(len(LRD)):
        l,r,d=LRD[i]
        if l in x and r not in x:
            x[r] = x[l] +d
            LRD.pop(i)
            break
        elif r in x and l not in x:
            x[r] = x[l] +d
            LRD.pop(i)
            break
        elif l in x and r in x:
            if x[l] +d != x[r]:
                flag=False
                break
            else:
                LRD.pop(i)
                break
    if ct==len(LRD):
        break

print("Yes No".split()[1-flag])

Fixed submission:
import queue,sys
# 解説読んだ後
N,M=map(int,input().split())
# networkを作る
G={}
LRD=[]
for i in range(1,N+1):
    G[i]={}
for i in range(M):
    l,r,d=map(int,input().split())
    LRD.append((l,r,d))
    G[l][r]=d
    G[r][l]=-d
if M==0:
    print("Yes")
    sys.exit()
notvisit=set(range(1,N+1))
Q=queue.Queue()
x={}
while notvisit:
    current=notvisit.pop()
    Q.put(current)
    x[current]=0
    while Q.qsize():
        nex=Q.get()
        for k,v in G[nex].items():
            if k in x:
                if x[k]!= x[nex]+G[nex][k]:
                    print("No")
                    sys.exit()
            else:
                x[k]=x[nex]+G[nex][k]
                Q.put(k)
                notvisit.remove(k)
print("Yes")