Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
sys.setrecursionlimit(10**6)
N,M=map(int,input().split())

D=[]
P=[[i,0]for i in range(N+1)]
C=[1 for i in range(N+1)]
A=[0]

for i in range(M):
    l,r,d=map(int,input().split())
    P[r]=[l,d]
    D.append([l,r,d])
#print(P)
def find(a,b):
    if c[a]==0:
        return a,b
    elif a==P[a][0]:
        return a,b
    else:
        c[a]=0
        return find(P[a][0],b+P[a][1])
for i in range(1,N+1):
    c=copy.deepcopy(C)
    A.append(find(i,0))
#print(A)
for i in range(M):
    if A[D[i][1]][1]-A[D[i][0]][1]!=D[i][2]:
        print("No")
        exit()
print("Yes")


Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,M=map(int,input().split())

C=[0 for i in range(N+1)]
L=[[]for i in range(N+1)]
A=[10**15 for i in range(N+1)]
B=[]

for i in range(M):
    l,r,d=map(int,input().split())
    B.append([l,r,d])
    C[r]=1
    L[l].append([l,r,d])
for i in range(N+1):
    if C[i]==0:
        A[i]=0
for i in range(1,N+1):
    if A[i]==0:
        if len(L[i])>0:
            Q=[]
            for l,r,d in L[i]:
                Q.append([A[i]+d,r,l])
            #print(Q)
            heapq.heapify(Q)
            for j in range(10**6):
                if len(Q)==0:
                    break
                else:
                    q=Q[0]
                    if A[q[1]]>=q[0]:
                        A[q[1]]=q[0]
                        for k in L[q[1]]:
                            heapq.heappush(Q,[q[0]+k[2],k[1],k[0]])
                heapq.heappop(Q)
#print(C)
#print(A)
for i in range(M):

    if A[B[i][1]]!=A[B[i][0]]+B[i][2]:
        print("No")
        exit()
print("Yes")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

N,M=map(int,input().split())

P=[i for i in range(N+1)]
r=[0 for i in range(N+1)]

def find(a):
    if a==P[a]:
        pass
    else:
        return find(P[a])
        
def union(a,b,c):
    P[b]=a
    r[b]=c
    
def find2(a,b):
    if a==P[a]:
        return b+r[a]
    else:
        return find2(P[a],b+r[a])
L=[]
for i in range(M):
    a,b,c=map(int,input().split())
    union(a,b,c)
    L.append([a,b,c])
    
for i in range(1,N+1):
    r[i]=find2(i,0)
    
#print(r)
#print(P)

for i in L:
    if r[i[0]]!=r[i[1]]-i[2]:
        print(i)
        print("No")
        exit()
print("Yes")
    


Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
P=[i for i in range(N+1)]
L=[0 for i in range(N+1)]
Q=[]
def find(a):
    if P[a]==a:
        return a
    else:
        return find(P[a])

def union(b,c,d):
    B=find(b)
    C=find(c)
    P[C]=P[B]
    L[c]=L[b]+d

for i in range(M):
    l,r,d=map(int,input().split())
    Q.append([l,r,d])
    union(l,r,d)
#print(P)
#print(L)

for i in Q:
    if L[i[1]]-L[i[0]]==i[2]:
        continue
    else:
        print("No")
        exit()
print("Yes")

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N,M=map(int,input().split())

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")