Problem:


Score : 400 points

Problem Statement

There are N people standing on the x-axis.
Let the coordinate of Person i be x_i.
For every i, x_i is an integer between 0 and 10^9 (inclusive).
It is possible that more than one person is standing at the same coordinate.

You will given M pieces of information regarding the positions of these people.
The i-th piece of information has the form (L_i, R_i, D_i).
This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.

It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.

Constraints

1 \leq N \leq 100 000

0 \leq M \leq 200 000

1 \leq L_i, R_i \leq N (1 \leq i \leq M)

0 \leq D_i \leq 10 000 (1 \leq i \leq M)

L_i \neq R_i (1 \leq i \leq M)

If i \neq j, then (L_i, R_i) \neq (L_j, R_j) and (L_i, R_i) \neq (R_j, L_j).

D_i are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M

Output

If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.

Sample Input 1

3 3
1 2 1
2 3 1
1 3 2

Sample Output 1

Yes

Some possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).

Sample Input 2

3 3
1 2 1
2 3 1
1 3 5

Sample Output 2

No

If the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.

Sample Input 3

4 3
2 1 1
2 3 5
3 4 2

Sample Output 3

Yes

Sample Input 4

10 3
8 7 100
7 9 100
9 8 100

Sample Output 4

No

Sample Input 5

100 0

Sample Output 5

Yes



Sample input:
3 3
1 2 1
2 3 1
1 3 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split(" "))
l = np.zeros(m, dtype=np.int)
r = np.zeros(m, dtype=np.int)
d = np.zeros(m, dtype=np.int)
for i in range(m):
    l[i], r[i], d[i] = map(int, input().split(" "))
    if(l[i] > r[i]):
        d[i] = d[i] * (-1)

pos = np.zeros(n, dtype=np.int)

for i in range(m):
    if(pos[l[i]-1] == 0 and pos[r[i]-1] == 0):
        pos[l[i]-1] = 1
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] != 0 and pos[r[i]-1] == 0):
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] == 0 and pos[r[i]-1] != 0):
        pos[l[i]-1] = pos[r[i]-1] - d[i]
    else:
        if(pos[r[i]-1] - pos[l[i]-1] != d[i]):
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
data = []
for i in range(m):
    data.append(list(map(int, input().split())))


if m == 0:
    print('Yes')
else:
    extended = np.array(data, dtype='int64')

    coeffs = extended[:,0:2]

    r_ex = np.linalg.matrix_rank(extended)
    r_cf = np.linalg.matrix_rank(coeffs)

    # print("r_ex = {}".format(r_ex))
    # print("r_cf = {}".format(r_cf))

    print('Yes' if r_ex == r_cf else 'No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
nums={}
ans=True
if m>0:
    for p in range(m):
        l,r,d=input().split()
        if nums.get(l)==None:
            nums[l]=1
        if nums.get(r)==None:
            nums[r]=nums[l]+int(d)
        else:
            if nums[r]!=nums[l]+int(d):
                ans=False
                break

    if ans:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, M = map(int, raw_input().split())
l, r, d = [], [], []

for _ in range(M):
    _l, _r, _d = map(int, raw_input().split())
    l.append(_l)
    r.append(_r)
    d.append(_d)

# info = np.array([l, r], dtype=np.int64)
# d = np.array(d, dtype=np.int32)

X = np.zeros((N, ), dtype=np.int64)
is_accessed = np.zeros((N, ), dtype=np.bool)

# for i in range(0, M):
#     find_person = info[0, i]
#     ind_x, ind_y = np.where(info == find_person)
#     if len(ind_x) > 1:
# print X

if M > 0:
    is_accessed[r[0] - 1], is_accessed[l[0] - 1] = True, True
    # X[l[0]] = 0
    X[r[0] - 1] = d[0]
    # print X, is_accessed
    for i in range(1, M):
        # print X, is_accessed
        if is_accessed[l[i] - 1] and is_accessed[r[i] - 1]:
            if X[r[i] - 1] != X[l[i] - 1] + d[i]:
                print 'No'
                exit()
        elif is_accessed[r[i] - 1] and not is_accessed[l[i] - 1]:
            X[l[i] - 1] = X[r[i] - 1] - d[i]
            is_accessed[l[i] - 1] = True
        elif is_accessed[l[i] - 1] and not is_accessed[r[i] - 1]:
            X[r[i] - 1] = X[l[i] - 1] + d[i]
            is_accessed[r[i] - 1] = True
        else:
            X[r[i] - 1] = X[l[i] - 1] + d[i]
            is_accessed[r[i] - 1], is_accessed[l[i] - 1] = True, True

print 'Yes'

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import numpy as np
def solve():
  
  ans=np.random.random()
  #print(ans)
  if ans <= 0.5:
    ans ="Yes"
  else:
    ans ="No"


  return ans
 
if __name__ == '__main__':
  ans = solve()
  print(ans, flush=True)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))

LRD = [list(map(int, input().split(' '))) for _ in range(M)]
new_LRD = sorted(LRD, key=lambda x: x[0])

comp = [False] * (N + 1)

cond = True
hold = []

for i in range(M):
    l = new_LRD[i][0]
    r = new_LRD[i][1]
    d = new_LRD[i][2]
    if i == 0:
        comp[l] = 0
        comp[r] = d     
    else:
        if not isinstance(comp[l], bool):
            if isinstance(comp[r], bool):
                  comp[r] = (comp[l] + d)
            else:
                if comp[r] != (comp[l] + d):
                    cond = False
                    break
                    
        else:
            if not isinstance(comp[r], bool):
                comp[l] = (comp[r] - d)
                
            else:
                hold.append([l, r, d])
                

for i in range(len(hold)):
    l = hold[i][0]
    r = hold[i][1]
    d = hold[i][2]    
    if not isinstance(comp[l], bool):
        if isinstance(comp[r], bool):
              comp[r] = (comp[l] + d)
        else:
            if comp[r] != (comp[l] + d):
                cond = False
                break

    else:
        if not isinstance(comp[r], bool):
            comp[l] = (comp[r] - d)

        else:
            continue


if cond:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    temp=list(map(int,temp.split(" ")))
    p.append(temp)
p.sort()
print(p)
sys.exit()
if m!=0:
    temp=p[0]
    x=int(temp[0])
    y=int(temp[1])
    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    # for temp in p:
    #     x=int(temp[0])
    #     y=int(temp[1])    
    #     d=int(temp[2])
    #     if dis[x]==-1 and dis[y]==-1: #完全な新情報なら
    #         dis[x]=0
    #         dis[y]=d
    #     elif dis[x]==-1: #xだけ不明なら
    #         dis[x]=dis[y]-d
    #     elif dis[y]==-1:
    #         dis[y]=dis[x]+d
    #     if dis[y]!=dis[x]+d:
    #         # print (x)
    #         # print (y)
    #         # print (d)
    #         # print("No")
    #         # sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split(" "))
l = np.zeros(m, dtype=np.int)
r = np.zeros(m, dtype=np.int)
d = np.zeros(m, dtype=np.int)
for i in range(m):
    l[i], r[i], d[i] = map(int, input().split(" "))
    if(l[i] > r[i]):
        tmp = l[i]
        l[i] = r[i]
        r[i] = tmp

pos = np.zeros(n, dtype=np.int)

for i in range(m):
    if(pos[l[i]-1] == 0 and pos[r[i]-1] == 0):
        pos[l[i]-1] = 1
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] != 0 and pos[r[i]-1] == 0):
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] == 0 and pos[r[i]-1] != 0):
        pos[l[i]-1] = pos[r[i]-1] - d[i]
    else:
        if(pos[r[i]-1] - pos[l[i]-1] != d[i]):
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(int, input().split())
L = []
R = []
D = []
for i in range(M):
    k, l, m = map(int, input().split())
    L.append(k)
    R.append(l)
    D.append(m)

DP = [None] * 100001

inc = 0

ids = {}

for i, j, k in sorted(list(zip(L, R, D))):
    if DP[i] != None and DP[j] != None:
        if DP[i][1] != DP[j][1]:
            diff = (DP[i][0] + k) - DP[j][0]
            for l in ids[DP[j][1]]:
                DP[l][0] += diff
                DP[l][1] = DP[i][1]
            ids[DP[i][1]] += ids[DP[j][1]]
        if DP[i][1] == DP[j][1] and DP[j][0] != DP[i][0] + k:
            print('No')
            sys.exit()
    if DP[i] == None and DP[j] == None:
        DP[i] = [0, inc]
        DP[j] = [DP[i][0] + k, inc]
        ids[inc] = [i, j]
        inc += 1
    if DP[i] == None and DP[j] != None:
        DP[i] = [DP[j][0] - k, DP[j][1]]
        ids[DP[j][1]].append(i)
    if DP[i] != None and DP[j] == None:
        DP[j] = [DP[i][0] + k, DP[i][1]]
        ids[DP[i][1]].append(j)
    
print('Yes')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))

LRD = [list(map(int, input().split(' '))) for _ in range(M)]
new_LRD = sorted(LRD, key=lambda x: x[0])

comp = [False] * (N + 1)

cond = True

for i in range(M):
    l = new_LRD[i][0]
    r = new_LRD[i][1]
    d = new_LRD[i][2]
    
    if i == 0:
        comp[l] = 0
        comp[r] = d     
    else:
        if not isinstance(comp[l], bool):
            if isinstance(comp[r], bool):
                  comp[r] = (comp[l] + d)
            else:
                if comp[r] != (comp[l] + d):
                    cond = False
                    break
                    
        else:
            if not isinstance(comp[r], bool):
                comp[l] = (comp[r] - d)
                
            else:
                continue
                

if cond:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    temp=list(map(int,temp.split(" ")))
    p.append(temp)
p.sort()

if m!=0:
    temp=p[0]
    x=int(temp[0])
    y=int(temp[1])
    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    for temp in p:
        x=int(temp[0])
        y=int(temp[1])    
        d=int(temp[2])
        if dis[x]==-1 and dis[y]==-1: #完全な新情報なら
            dis[x]=0
            dis[y]=d
        elif dis[x]==-1: #xだけ不明なら
            dis[x]=dis[y]-d
        elif dis[y]==-1:
            dis[y]=dis[x]+d
        if dis[y]!=dis[x]+d:
            # print (x)
            # print (y)
            # print (d)
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
import sys

VAL = 100

N, M = map(int, raw_input().split())
arr = []
for i in range(M):
    arr.append(map(int, raw_input().split()))
dic = {}

for i in range(M):
    l = arr[i][0]
    r = arr[i][1]
    d = arr[i][2]
    isr = False
    isl = False
    if r not in dic:
        dic[r] = r
    else:
        key_r = dic[r]
        isr = True
    if l not in dic:
        dic[l] = r - d
    else:
        key_l = dic[l]
        isl = True


    if isr and not isl:
        if key_r - l != d:
            print "No"
            sys.exit()
    elif not isr and isl:
        if r - key_l != d:
            print "No"
            sys.exit()
    elif isr and isl:
        if key_r - key_l != d:
            print "No"
            sys.exit()
    else:
        if r - l != d:
            print "No"
            sys.exit()

print "Yes"

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
humans = [None for _ in range(N)]

result = "Yes"

for _ in range(M):
    L,R,D = map(int,input().split())
    if humans[L-1] == None:
        if humans[R-1] == None:
            humans[L-1] = 0
        else:
            humans[L-1] = humans[R-1]-D

    if humans[R-1] == None:
        humans[R-1] = humans[L-1]+D
    else:
        if humans[R-1] != humans[L-1]+D:
            result = "No"

print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if M == 0:
    print("Yes")
else:
    C = np.array([list(map(int, input().split())) for _ in range(M)])

    C = np.array(C)
    for m in range(M):
        if C[m][1] < C[m][0]:
            C[m][0], C[m][1] = C[m][1], C[m][0]
            C[m][2] = -C[m][2]
    C = C[C[:, 0].argsort(), :]

    pos = {n: False for n in range(1, N + 1)}
    flag = True
    for m in range(M):
        if pos[C[m][0]] is False and pos[C[m][1]] is False:
            pos[C[m][0]] = 0
            pos[C[m][1]] = C[m][2]
        elif pos[C[m][0]] is not False and pos[C[m][1]] is not False:
            if pos[C[m][1]] - pos[C[m][0]] != C[m][2]:
                flag = False
                break
        elif pos[C[m][0]] is False:
            pos[C[m][0]] = pos[C[m][1]] - C[m][2]
        else:
            pos[C[m][1]] = pos[C[m][0]] + C[m][2]

    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N_PEOPLE, N_INFO = list(map(int, input().split()))

info_list = []
for i in range(N_INFO):
  l, r, d = list(map(int, input().split()))
  info_list.append({
    "left":  l-1,
    "right": r-1,
    "dist":  d
  })

# 与えられた条件を満たす場合があるか
fulfill_conditions = True

# 各人の位置(不定の場合は-1)
locations = [-1] * N_PEOPLE

# 各人が登場したか
appeared = []

# 各人の関係グラフ
relation = defaultdict(lambda: [])

for info in info_list:
  # 左右の人物が共に初登場なら，とりあえずleftを0において，rightを距離の分だけ離す
  if info["left"] not in appeared and info["right"] not in appeared:
    locations[info["left"]] = 0
    locations[info["right"]] = info["dist"]

    appeared.append(info["left"])
    appeared.append(info["right"])

    relation[info["left"]].append(info["right"])
    relation[info["right"]].append(info["left"])

    continue

  # 左の人物だけが初登場なら，rightの人物の位置から見てdist分左におく
  if info["left"] not in appeared and info["right"] in appeared:
    locations[info["left"]] = locations[info["right"]] - info["dist"]

    # 左に置くと範囲外になるなら，それを0に設置して，
    # 超過した分だけ他の人を右にずらす
    if locations[info["left"]] < 0:
      exceeded_dist = -1 * locations[info["left"]]
      locations[info["left"]] = 0

      for index in relation[info["right"]]:
        locations[index] += exceeded_dist

      if max(locations) > 10**9:
        fulfill_conditions = False
        break

    appeared.append(info["left"])
    relation[info["left"]].append(info["right"])
    relation[info["right"]].append(info["left"])

    continue


  # 右の人物だけが初登場なら，leftの人物から見てdist分右におく
  if info["left"] in appeared and info["right"] not in appeared:
    locations[info["right"]] = locations[info["left"]] + info["dist"]

    # 右に置くと範囲外になるなら，それを10**9に設置して，
    # 超過した分だけ他の人を左にずらす
    if locations[info["right"]] > 10**9:
      exceeded_dist = locations[info["right"]] - (10**9)
      locations[info["right"]] = 10**9

      for index in relation[info["left"]]:
        locations[index] += exceeded_dist

      if min(locations) < 0:
        fulfill_conditions = False
        break

    appeared.append(info["right"])
    relation[info["left"]].append(info["right"])
    relation[info["right"]].append(info["left"])

    continue

  # 両方の人物が既出なら，距離が正しいかチェックする
  # 正しくなければアウト
  if info["left"] in appeared and info["right"] in appeared:
    if locations[info["right"]] - locations[info["left"]] != info["dist"]:

      fulfill_conditions = False
      break

    relation[info["left"]].append(info["right"])
    relation[info["right"]].append(info["left"])

if fulfill_conditions:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import itertools
n, m = map(int, input().split())
Gr = {}
R = []
for i in range(m):
    l, r, d = map(int, input().split())
    Gr[(l - 1, r - 1)] = d
    Gr[(r - 1, l - 1)] = -d


rec = True
for i, j in itertools.product(Gr, Gr):
    if i[1] == j[0] and (i[0], j[1]) in Gr:
        print((i[0], j[1]))
        if Gr[(i[0], j[1])] != Gr[i] + Gr[j]:
            rec = False

if rec:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))

LRD = [list(map(int, input().split(' '))) for _ in range(M)]
new_LRD = sorted(LRD, key=lambda x: x[0])

comp = [False] * (N + 1)

cond = True

for i in range(M):
    l = new_LRD[i][0]
    r = new_LRD[i][1]
    d = new_LRD[i][2]
    print(l,r,d)
    if i == 0:
        comp[l] = 0
        comp[r] = d     
    else:
        if not isinstance(comp[l], bool):
            if isinstance(comp[r], bool):
                  comp[r] = (comp[l] + d)
            else:
                if comp[r] != (comp[l] + d):
                    cond = False
                    break
                    
        else:
            if not isinstance(comp[r], bool):
                comp[l] = (comp[r] - d)
                
            else:
                continue
                

if cond:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
humans = [None for _ in range(N)]

result = "Yes"

for _ in range(M):
    L,R,D = map(int,input().split())
    if humans[L-1] == None:
        if humans[R-1] == None:
            humans[L-1] = 0
        else:
            humans[L-1] = humans[R-1]-D
    else:
        if humans[R-1] == None:
            humans[R-1] = humans[L-1]+D
        else:
            if humans[R-1] != humans[L-1]+D:
                result = "No"

print(result)

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(int, input().split())
L = []
R = []
D = []
for i in range(M):
    k, l, m = map(int, input().split())
    L.append(k)
    R.append(l)
    D.append(m)

DP = [None] * 100001

inc = 0

ids = {}

for i, j, k in sorted(list(zip(L, R, D))):
    if DP[i] != None and DP[j] != None:
        if DP[i][1] != DP[j][1]:
            diff = (DP[i][0] + k) - DP[j][0]
            for l in ids[DP[j][1]]:
                DP[l][0] += diff
                DP[l][1] = DP[l][1]
        if DP[i][1] == DP[j][1] and DP[j][0] != DP[i][0] + k:
            print('No')
            sys.exit()
    if DP[i] == None and DP[j] == None:
        DP[i] = [0, inc]
        DP[j] = [DP[i][0] + k, inc]
        ids[inc] = [i, j]
        inc += 1
    if DP[i] == None and DP[j] != None:
        DP[i] = [DP[j][0] - k, DP[j][1]]
        ids[DP[j][1]].append(i)
    if DP[i] != None and DP[j] == None:
        DP[j] = [DP[i][0] + k, DP[i][1]]
        ids[DP[i][1]].append(j)
    
print('Yes')

Submission status: Wrong Answer

Solution code:
x = {}
n, m = map(int, raw_input().split())
flag = True
for _ in xrange(m):
    l, r, d = map(int, raw_input().split())
    if l in x:
        if r in x:
            if x[l][1] + d != x[r][1]:
                if x[l][0] == x[r][0]:
                    flag = False
                else:
                    for k, v in x.iteritems():
                        if v[0] == r:
                            x[k] = (x[l][0], v[1] + x[l][1] + d)
        else:
            x[r] = (x[l][0], x[l][1] + d)
    else:
        x[l], x[r] = (l, 0), (l, d)
print x
print 'Yes' if flag else 'No'

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M = map(int, input().split())
x = [-1] * N
ans = True
t = [0] * M
for i in range(M):
    L, R, D = map(int, input().split())
    t[i] = [L - 1, R - 1, D]
t.sort(key=lambda x:x[0])
t.sort(key=lambda x:x[1])
for L, R, D in t:
    if x[R] == -1:
        if x[L] == -1:
            x[L] = 0
        x[R] = x[L] + D
    elif x[L] == -1:
        x[L] = x[R] - D
    else:
        if x[R] - x[L] != D:
            ans = False
m = min(x)
x = list(map(lambda y: y - m, x))
print(x)
print(('No', 'Yes')[ans and max(x) <= 10 ** 9])

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    p.append(temp)
p.sort()
if m!=0:
    temp=p[0].split(" ")
    x=int(temp[0])
    y=int(temp[1])

    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    for temp in p:
        temp=temp.split(" ")
        x=int(temp[0])
        y=int(temp[1])    
        d=int(temp[2])
        if dis[x]==-1 and dis[y]==-1: #完全な新情報なら
            dis[x]=0
            dis[y]=d
        elif dis[x]==-1: #xだけ不明なら
            dis[x]=dis[y]-d
        elif dis[y]==-1:
            dis[y]=dis[x]+d
        if dis[y]!=dis[x]+d:
            # print (x)
            # print (y)
            # print (d)
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n,m = map(int,raw_input().split(" "))

data = []
if m == 0:
  print "Yes"
  exit(0)

for a in range(m):
  l,r,d = map(int,raw_input().split(" "))
  if l > r:
    data.append([r,l,-d])
  else:
    data.append([l,r,d])
data.sort()

p = {}

for q in data:
  if q[0] not in p:
    p[q[0]] = 0
  if q[1] in p:
    if p[ q[1] ] != p[ q[0] ] + q[2]:
      print "No"
      exit(0)
  p[ q[1] ] = p[ q[0] ] + q[2]

print "Yes"

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split(" "))
l = np.zeros(m, dtype=np.int)
r = np.zeros(m, dtype=np.int)
d = np.zeros(m, dtype=np.int)
for i in range(m):
    l[i], r[i], d[i] = map(int, input().split(" "))

pos = np.zeros(n, dtype=np.int)

for i in range(m):
    if(pos[l[i]-1] == 0 and pos[r[i]-1] == 0):
        pos[l[i]-1] = 1
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] != 0 and pos[r[i]-1] == 0):
        pos[r[i]-1] = pos[l[i]-1] + d[i]
    elif(pos[l[i]-1] == 0 and pos[r[i]-1] != 0):
        pos[l[i]-1] = pos[r[i]-1] - d[i]
    else:
        if(pos[r[i]-1] - pos[l[i]-1] != d[i]):
            print("No")
            exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
m = int(a[1])
 
x = [-1 for k in range(n)]
ans = "Yes"
 
 
for i in range(m):
    b = input().split()
    if i == 0:
        x[int(b[0])-1] = 0
        x[int(b[1])-1] = x[int(b[0])-1] + int(b[2])
 
    else:
        if (x[int(b[1])-1] != -1) and (x[int(b[1])-1] != (x[int(b[0])-1] + int(b[2]))):
            ans = "No"
            break
        else:
            x[int(b[1])-1] = x[int(b[0])-1] + int(b[2])
        	
 
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
k = [None] * (n+1)
ans = 'Yes'
h = [list(map(int, input().split())) for i in range(m)]
h = sorted(h,key=lambda x: (x[0],[1]))
for i,(l,r,d) in enumerate(h):
    if i == 0: 
        k[l] = 0
        k[r] = d
    else:
        if k[l] is None and k[r] is None:
            continue
        elif k[l] is not None and k[r] is None:
            k[r] = k[l] + d
        elif k[l] is None and k[r] is not None:
            k[l] = k[r] + d
    if k[r] - k[l] != d:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = list(map(int, input().split()))
data = []
for i in range(m):
    data.append(list(map(int, input().split())))


if m == 0:
    print('Yes')
else:
    extended = np.array(data)

    coeffs = extended[:,0:2]

    r_ex = np.linalg.matrix_rank(extended)
    r_cf = np.linalg.matrix_rank(coeffs)

    print('Yes' if r_ex == r_cf else 'No')

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
humans = [None for _ in range(N)]

result = "Yes"

for _ in range(M):
    L,R,D = map(int,input().split())
    if humans[L-1] == None:
        humans[L-1] = 0
    if humans[R-1] == None:
        humans[R-1] = humans[L-1]+D
    else:
        if humans[R-1] != humans[L-1]+D:
            result = "No"

print(result)

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
if M==0:
  print('Yes')
  sys.exit()
people=N*[1145141919]
mlist=[]
for i in range(M):
  L,R,D=map(int,input().split())
  mlist.append([L,R,D])
people[mlist[0][0]-1]=0
people[mlist[0][1]-1]=mlist[0][2]
del mlist[0]
tmp1=-1
tmp2=-2
while True:
  if len(mlist)==0:break
  elif tmp1==tmp2:
    people[mlist[0][0]-1]=0
    people[mlist[0][1]-1]=mlist[0][2]
    del mlist[0]
  for i in mlist:
    if people[i[0]-1]!=1145141919 and people[i[1]-1]==1145141919:
      people[i[1]-1]=people[i[0]-1]+i[2]
      mlist.remove([i[0],i[1],i[2]])
    elif people[i[1]-1]!=1145141919 and people[i[0]-1]==1145141919:
      people[i[0]-1]=people[i[1]-1]-i[2]
      mlist.remove([i[0],i[1],i[2]])
    else:
      if people[i[1]-1]-people[i[0]-1]!=i[2]:
        print('No')
        sys.exit()
      mlist.remove([i[0],i[1],i[2]])
  tmp1=tmp2
  tmp2=len(mlist)
print('Yes')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = []
R = []
D = []
for i in range(M):
    tmp = input().split()
    L.append(int(tmp[0]))
    R.append(int(tmp[1]))
    D.append(int(tmp[2]))

pos = {}
ans = "Yes"

for i in range(N):
    pos[i + 1] = 0

for i in range(M):
    l = L[i]
    r = R[i]
    d = D[i]
    if(pos[l] > pos[r]):
        ans = "No"
    elif(pos[r] == 0):
        pos[r] = pos[l] + d
    else:
        if(pos[l] + d != pos[r]):
            ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    p.append(temp)
p.sort()
if m!=0:
    temp=p[0].split(" ")
    x=int(temp[0])
    y=int(temp[1])

    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    for temp in p:
        temp=temp.split(" ")
        x=int(temp[0])
        y=int(temp[1])    
        d=int(temp[2])
        if dis[x]==-1:
            dis[x]=0
        if dis[y]==-1:
            dis[y]=dis[x]+d
        if dis[y]!=dis[x]+d:
            # print (x)
            # print (y)
            # print (d)
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
num = [int() for i in input().split()]
if num[0] % 2 == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
a = input().split()
n = int(a[0])
m = int(a[1])

x = [-1 for k in range(n)]
ans = "Yes"


for i in range(m):
    b = input().split()
    if i == 0:
        x[int(b[0])-1] = 0
        x[int(b[1])-1] = x[int(b[0])-1] + int(b[2])
        print(x)
    else:
        if (x[int(b[1])-1] != -1) and (x[int(b[1])-1] != (x[int(b[0])-1] + int(b[2]))):
            ans = "No"
            break
        else:
        	x[int(b[1])-1] = x[int(b[0])-1] + int(b[2])
        	print(x)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    p.append(temp)
p.sort()
if m!=0:
    temp=p[0].split(" ")
    x=int(temp[0])
    y=int(temp[1])

    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    for temp in p:
        temp=temp.split(" ")
        x=int(temp[0])
        y=int(temp[1])    
        d=int(temp[2])
        if dis[x]==-1:
            dis[x]=0
        elif dis[y]==-1:
            dis[y]=dis[x]+d
        elif dis[y]!=dis[x]+d:
            # print (x)
            # print (y)
            # print (d)
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
f = lambda :list(map(int,input().split()))
N,M = f()
L,R,D = [],[],[]
posit = [0]*N
changed = [False]*N
flag = False

if M <= 1:
    print("Yes")
    sys.exit()

for i in range(M):
    l,r,d = f()
    L.append(l)
    R.append(r)
    D.append(d)

pivot = L[0]

for i in range(M):
    l, r, d = L[i]-1,R[i]-1,D[i]
    if r+1 == pivot:
        if changed[l] and posit[r] - d != posit[l]:
            flag = True
            break
        else:
            posit[l] = posit[r] - d
            changed[l] = True
    else:
        if changed[r] and posit[l] + d != posit[r]:
            flag = True
            break
        else:
            posit[r] = posit[l] + d
            changed[r] = True

if flag:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n,m = map(int,raw_input().split(" "))

data = []
if m == 0:
  print "Yes"
  exit(0)

for a in range(m):
  l,r,d = map(int,raw_input().split(" "))
  if l > r:
    data.append([r,l,-d])
  else:
    data.append([l,r,d])
data.sort()

p = {}
p[data[0][0]] = 0

for q in data:
  if q[0] in p:
    if q[1] in p:
      if p[ q[1] ] != p[ q[0] ] + q[2]:
        print "No"
        exit(0)
    p[ q[1] ] = p[ q[0] ] + q[2]

print "Yes"

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
L = []
R = []
D = []
for i in range(M):
    tmp = input().split()
    L.append(int(tmp[0]))
    R.append(int(tmp[1]))
    D.append(int(tmp[2]))

pos = {}
ans = "Yes"

for i in range(N):
    pos[i + 1] = 0

for i in range(M):
    l = L[i]
    r = R[i]
    d = D[i]
    if(pos[r] == 0):
        pos[r] = pos[l] + d
    else:
        if(pos[l] + d != pos[r]):
            ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
m=int(temp[1])
# p=[[-1 for i in range(n)] for j in range(n)]
p=[]
dis=[-1]*(n+1)
for i in range(m):
    temp=input()
    p.append(temp)
p.sort()
if m!=0:
    temp=p[0].split(" ")
    x=int(temp[0])
    y=int(temp[1])

    d=int(temp[2])
    dis[x]=0
    dis[y]=d

    p.pop(0)

    for temp in p:
        temp=temp.split(" ")
        x=int(temp[0])
        y=int(temp[1])    
        d=int(temp[2])
        if dis[y]==-1:
            dis[y]=dis[x]+d
        elif dis[y]!=dis[x]+d:
            # print (x)
            # print (y)
            # print (d)
            print("No")
            sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
x = {}
n, m = map(int, raw_input().split())
if m == 0:
    print 'Yes'
    exit()
l, r, d = map(int, raw_input().split())
x[l], x[r] = 0, d
flag = True
dat = sorted([map(int, raw_input().split()) for _ in xrange(m - 1)], key = lambda x: x[0])
for _ in dat:
    if r in x:
        if x[r] != x[l] + d:
            flag = False
    else:
        x[r] = x[l] + d
print 'Yes' if flag else 'No'

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(int, input().split())
L = []
R = []
D = []
for i in range(M):
    k, l, m = map(int, input().split())
    L.append(k)
    R.append(l)
    D.append(m)

DP = [None] * 100001

again = []

for i, j, k in sorted(list(zip(L, R, D))):
    if DP[i] != None and DP[j] != None:
        if DP[j] != DP[i] + k:
            print('No')
            sys.exit()
    if DP[i] == None and DP[j] == None:
        again.append((i,j,k))
        # DP[i] = 0
        # DP[j] = DP[i] + k
    if DP[i] == None and DP[j] != None:
        DP[i] = DP[j] - k
    if DP[i] != None and DP[j] == None:
        DP[j] = DP[i] + k

for i, j, k in again:
    if DP[i] != None and DP[j] != None:
        if DP[j] != DP[i] + k:
            print('No')
            sys.exit()
    if DP[i] == None and DP[j] == None:
        DP[i] = 0
        DP[j] = DP[i] + k
    if DP[i] == None and DP[j] != None:
        DP[i] = DP[j] - k
    if DP[i] != None and DP[j] == None:
        DP[j] = DP[i] + k

print('Yes')