Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
Adj_list = [[] for _ in range(N) ]

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = G[v] + d
               stack.append(to)
           else:
               if G[to] != G[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = G[v] + d
               stack.append(to)
           else:
               if G[to] != G[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")


Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = G[v] + d
               stack.append(to)
           else:
               if G[to] != G[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
LRD = list(list(map(int,input().split())) for i in range(M))
#print(LRD)
d = {LRD[0][0]:0}

for i in range(M):
    if (LRD[i][0] in d) and (LRD[i][1] not in d):
          d[LRD[i][1]] = d[LRD[i][0]]+LRD[i][2]
    elif (LRD[i][0] in d) and (LRD[i][1] in d):
        if d[LRD[i][1]] != d[LRD[i][0]]+LRD[i][2]:
            print("No")
            exit()
    elif (LRD[i][0] not in d) and (LRD[i][1] in d):
        d[LRD[i][0]] = d[LRD[i][1]] - LRD[i][2]
    else:
        d[LRD[i][0]] = 0
        d[LRD[i][1]] = d[LRD[i][0]] + LRD[i][2]

print("Yes")

Fixed submission:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")