Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, m = map(int, raw_input().split())
    edge = {v:[] for v in range(1,n+1)}
    dist = {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        edge[l].append(r)
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que:
            u = que.pop(0)
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not (s,v) in path:
                    path[s,v] = d
                    if not used[v]:
                        que.append(v)
                    used[v] = True
                elif d != path[s,v]:
                    return False
    return True

print solve()

Fixed submission:
def solve():
    n, m = map(int, raw_input().split())
    edge = {v:[] for v in range(1,n+1)}
    dist = {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        edge[l].append(r)
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que:
            u = que.pop()
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not used[v]:
                    path[s,v] = d
                    que.append(v)
                    used[v] = True
                elif d != path[s,v]:
                    return False
    return True

print solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n, m = map(int, raw_input().split())
    edge, dist = {}, {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        if not l in edge:
            edge[l] = []
        edge[l].append(r)
        if not r in edge:
            edge[r] = []
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que != []:
            u = que.pop(0)
            if not u in edge:
                continue
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not (s,v) in path:
                    path[s,v] = d
                    used[v] = True
                    que.append(v)
                elif d != path[s,v]:
                    return False
    return True

print solve()

Fixed submission:
def solve():
    n, m = map(int, raw_input().split())
    edge = {v:[] for v in range(1,n+1)}
    dist = {}
    for i in range(m):
        l, r, d = map(int, raw_input().split())
        edge[l].append(r)
        edge[r].append(l)
        dist[l,r] = d
        dist[r,l] = -d
    return "Yes" if ok(edge, dist, n) else "No"

def ok(edge, dist, n):
    used = [False] * (n+1)
    used[0] = True
    path = {}
    for s in range(1, n+1):
        if used[s]:
            continue
        que = [s]
        path[s, s] = 0
        used[s] = True
        while que:
            u = que.pop()
            for v in edge[u]:
                d = path[s,u] + dist[u,v]
                if not used[v]:
                    path[s,v] = d
                    que.append(v)
                    used[v] = True
                elif d != path[s,v]:
                    return False
    return True

print solve()