Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5+5)
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
def dfs(x):
    for i in graph[x]:
        if x_list[i[0]]==INF:
            x_list[i[0]]=x_list[x]+i[1]
            dfs(i[0])
        else:
            if x_list[i[0]]==x_list[x]+i[1]:
                pass
            else:
                print('No')
                sys.exit()
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        dfs(i)
print('Yes')


Fixed submission:
import sys
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
stack=[]
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        stack.append(i)
        while len(stack)>0:
            now=stack.pop()
            for j in graph[now]:
                if x_list[j[0]]==INF:
                    x_list[j[0]]=x_list[now]+j[1]
                    stack.append(j[0])
                else:
                    if x_list[j[0]]==x_list[now]+j[1]:
                        pass
                    else:
                        print('No')
                        sys.exit()
print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**10
x_list=[INF]*n
def dfs(x):
    for i in graph[x]:
        if x_list[i[0]]==INF:
            x_list[i[0]]=x_list[x]+i[1]
            dfs(i[0])
        else:
            if x_list[i[0]]==x_list[x]+i[1]:
                pass
            else:
                print('No')
                sys.exit()
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        dfs(i)
print('Yes')


Fixed submission:
import sys
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
stack=[]
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        stack.append(i)
        while len(stack)>0:
            now=stack.pop()
            for j in graph[now]:
                if x_list[j[0]]==INF:
                    x_list[j[0]]=x_list[now]+j[1]
                    stack.append(j[0])
                else:
                    if x_list[j[0]]==x_list[now]+j[1]:
                        pass
                    else:
                        print('No')
                        sys.exit()
print('Yes')

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**10
x_list=[INF]*n
import sys
def dfs(x):
    for i in graph[x]:
        if x_list[i[0]]==INF:
            x_list[i[0]]=x_list[x]+i[1]
            dfs(i[0])
        else:
            if x_list[i[0]]==x_list[x]+i[1]:
                pass
            else:
                print('No')
                sys.exit()
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        dfs(i)
print('Yes')


Fixed submission:
import sys
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
stack=[]
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        stack.append(i)
        while len(stack)>0:
            now=stack.pop()
            for j in graph[now]:
                if x_list[j[0]]==INF:
                    x_list[j[0]]=x_list[now]+j[1]
                    stack.append(j[0])
                else:
                    if x_list[j[0]]==x_list[now]+j[1]:
                        pass
                    else:
                        print('No')
                        sys.exit()
print('Yes')