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: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    for i in range(n):
        if x[i]:
            continue
        stack = [i]
        x[i] = 0
        while len(stack):
            v = stack.pop()
            for u, d in g[v]:
                if not x[u]:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = ((map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    for i in range(n):
        if x[i]:
            continue
        stack = [i]
        x[i] = 0
        while len(stack) > 0:
            v = stack.pop()
            for u, d in g[v]:
                if not x[u]:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = ((map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    while None in x:
        inone = x.index(None)
        stack = [inone]
        x[inone] = 0
        while len(stack) > 0:
            v = stack.pop()
            for u, d in g[v]:
                if not x[u]:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = tuple(list(map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for lrd in lrds:
        lrd[0] -= 1
        lrd[1] -= 1
        l, r, d = lrd
        g[l].append((r, d))
        g[r].append((l, -d))

    while None in x:
        inone = x.index(None)
        stack = [inone]
        x[inone] = 0
        while len(stack) > 0:
            i = stack.pop()
            for j, d in g[i]:
                if not x[j]:
                    stack.append(j)
                    x[j] = x[i] + d

    for l, r, d in lrds:
        if x[r] - x[l] != d:
            print('No')
            sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
x = [-1 for i in range(n+1)]
xGroup = [0 for i in range(n+1)]
groupNum = 0
result = True
for i in range(m):
    l, r, d = list(map(int, input().split()))
    if xGroup[l] == 0:
        if xGroup[r] == 0:
            groupNum += 1
            x[l] = 0
            xGroup[l] = groupNum
            x[r] = d
            xGroup[r] = groupNum
        else:
            x[l] = x[r] - d
            xGroup[l] = xGroup[r]
    else:
        if xGroup[r] == 0:
            x[r] = x[l] + d
            xGroup[r] = xGroup[l]
        else:
            if x[r] - x[l] != d:
                result = False
for i in range(1, groupNum+1):
    min = 10001
    max = -1
    for j in range(1, n+1):
        if xGroup[j] == i:
            if x[j] < min:
                min = x[j]
            elif x[j] > max:
                max = x[j]
    if max-min > 10000:
        result = False

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

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
x = [-1 for i in range(n+1)]
xGroup = [0 for i in range(n+1)]
groupNum = 0
result = True
for i in range(m):
    l, r, d = list(map(int, input().split()))
    if xGroup[l] == 0:
        if xGroup[r] == 0:
            groupNum += 1
            x[l] = 0
            xGroup[l] = groupNum
            x[r] = d
            xGroup[r] = groupNum
        else:
            x[l] = x[r] - d
            xGroup[l] = xGroup[r]
    else:
        if xGroup[r] == 0:
            x[r] = x[l] + d
            xGroup[r] = xGroup[l]
        else:
            if x[r] - x[l] != d:
                result = False
for i in range(groupNum):
    min = 10001
    max = -1
    for j in range(1, n+1):
        if x[j] < min:
            min = x[j]
        elif x[j] > max:
            max = x[j]
    if max-min > 10000:
        result = False

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
g = defaultdict(list)

n, m = map(int, input().split())
if m==0:
    print('Yes')
    exit()
for i in range(m):
    l, r, d = map(int, input().split())
    g[l].append((r, d))
    g[r].append((l, -1*d))
    
visited = {}
vv = {k:None for k in g.keys()}
def dfs(v):
    stack = []
    visited[v] = True
    stack.append((v,0))
    while len(stack)!= 0:
        v,w = stack.pop()
        vv[v] = w
        for c,d in g[v]:
            if not visited.get(c, False):
                visited[c] = True
                stack.append((c,w+d))

f = list(g.keys())[0]
not_visited = g.keys()
while True:
    dfs(f)
    not_visited = list(set(not_visited) - set(visited.keys()))
    if not_visited == []: break
    else: f = not_visited[0]

for k in g.keys():
    v = vv[k]
    for c,w in g[k]:
        if not v + w == vv[c]:
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
g = defaultdict(list)

n, m = map(int, input().split())
if m==0:
    print('Yes')
    exit()
for i in range(m):
    l, r, d = map(int, input().split())
    g[l].append((r, d))
    g[r].append((l, -1*d))
    
visited = {}
vv = {k:None for k in g.keys()}
def dfs(v):
    stack = []
    visited[v] = True
    stack.append((v,0))
    while len(stack)!= 0:
        v,w = stack.pop()
        vv[v] = w
        for c,d in g[v]:
            if not visited.get(c, False):
                visited[c] = True
                stack.append((c,w+d))

f = list(g.keys())[0]
while True:
    dfs(f)
    not_visited = list(set(g.keys()) - set(visited.keys()))
    if not_visited == []: break
    else: f = not_visited[0]

for k in g.keys():
    v = vv[k]
    for c,w in g[k]:
        if not v + w == vv[c]:
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int,input().split()))
k = [[-1 for i in range(n)] for j in range(n)]
for i in range(m):
	l, r, d = list(map(int,input().split()))
	k[l - 1][r - 1] = d
key = 0

for i in range(n):
	for j in range(n):
		if(k[i][j] != -1):
			for p in range(n):
				if(k[j][p] != -1):
					if(k[i][p] == -1):
						k[i][p] = k[i][j] + k[j][p]
					elif(k[i][p] != k[i][j] + k[j][p]):
						key = 1
if key == 1:
	print("No")
else:
	print("Yes")

Submission status: Time Limit Exceeded

Solution code:
def evaluate_positions(positions, cache, assume_origin_set, unevaluated_positions):
    has_conflict = False
    origin_set = assume_origin_set
    for position_data in positions:
        l, r, d = position_data
        if cache[l] != -1 and cache[r] != -1:
            if cache[r] - cache[l] != d:
                has_conflict = True
                break
        elif cache[l] == -1 and cache[r] != -1:
            cache[l] = cache[r] - d
        elif cache[l] != -1 and cache[r] == -1:
            cache[r] = cache[l] + d
        else:
            if not origin_set:
                cache[l] = 0
                cache[r] = d
                origin_set = True
            else:
                unevaluated_positions.append(position_data)
    return has_conflict

if __name__ == '__main__':
    n, m = list(map(int, input().split(" ")))
    cache = [-1 for _ in range(n + 1)]
    positions = []
    for _ in range(m):
        positions.append(list(map(int, input().split(" "))))
    unevaluated_positions = []

    has_conflict = False
    assume_origin_set = False
    while True:
        has_conflict = evaluate_positions(positions, cache, assume_origin_set, unevaluated_positions)
        assume_origin_set = True
        #print("{} vs {}".format(positions, unevaluated_positions))
        if has_conflict:
            break
        if len(unevaluated_positions) == 0:
            break
        if len(positions) == len(unevaluated_positions):
            assume_origin_set = False
        positions = unevaluated_positions
        unevaluated_positions = []

    print("No" if has_conflict else "Yes")

Submission status: Time Limit Exceeded

Solution code:
def evaluate_positions(positions, cache, assume_origin_set, unevaluated_positions):
    has_conflict = False
    origin_set = assume_origin_set
    for position_data in positions:
        l, r, d = position_data
        if cache[l] != -1 and cache[r] != -1:
            if cache[r] - cache[l] != d:
                has_conflict = True
                break
        elif cache[l] == -1 and cache[r] != -1:
            cache[l] = cache[r] - d
        elif cache[l] != -1 and cache[r] == -1:
            cache[r] = cache[l] + d
        else:
            if not origin_set:
                cache[l] = 0
                cache[r] = d
                origin_set = True
            else:
                unevaluated_positions.append(position_data)
    return has_conflict

def check_is_subset(container, subset):
    for elem in subset:
        if elem not in container:
            return False
    return True

if __name__ == '__main__':
    n, m = list(map(int, input().split(" ")))
    cache = [-1 for _ in range(n + 1)]
    positions = []
    for _ in range(m):
        positions.append(list(map(int, input().split(" "))))
    unevaluated_positions = []

    has_conflict = False
    assume_origin_set = False
    while True:
        has_conflict = evaluate_positions(positions, cache, assume_origin_set, unevaluated_positions)
        assume_origin_set = True
        #print("{} vs {}".format(positions, unevaluated_positions))
        if has_conflict:
            break
        if len(unevaluated_positions) == 0:
            break
        if check_is_subset(positions, unevaluated_positions) and check_is_subset(unevaluated_positions, positions):
            assume_origin_set = False
        positions = unevaluated_positions
        unevaluated_positions = []

    print("No" if has_conflict else "Yes")

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
import numpy as np


setrecursionlimit(10**6)

N, M = tuple(map(int, input().split()))
Ls = np.zeros((M,), dtype=int)
Rs = np.zeros((M,), dtype=int)
Ds = np.zeros((M,), dtype=int)

for i in range(M):
    Ls[i], Rs[i], Ds[i] = tuple(map(int, input().split()))

Ls = Ls - 1
Rs = Rs - 1

adjacency_list = []
for i in range(N):
    adjacency_list.append([])

for i in range(M):
    adjacency_list[Ls[i]].append((Rs[i], Ds[i]))
    adjacency_list[Rs[i]].append((Ls[i], -Ds[i]))

visited = np.zeros(N, dtype=bool)
weights = np.zeros(N, dtype=int)
to_be_visited = []


def DFS(node_index):
    global adjacency_list, visited, weights, to_be_visited
    adjacent_node_information = adjacency_list[node_index]
    for adjacent_node_index, adjacent_edge_weight in adjacent_node_information:
        if not visited[adjacent_node_index]:
            visited[adjacent_node_index] = True
            to_be_visited.append(adjacent_node_index)
            weights[adjacent_node_index] = weights[node_index] + adjacent_edge_weight

    if len(to_be_visited) == 0:
        return 0
    else:
        DFS(to_be_visited.pop())

pointer = 0
for pointer in range(N):
    if not visited[pointer]:
        to_be_visited.append(pointer)
        DFS(pointer)

for i in range(M):
    if weights[Rs[i]] - weights[Ls[i]] != Ds[i]:
        print("No")
        exit()

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
from sys import stdin
sys.setrecursionlimit(200002)
input = stdin.readline

INF = 10000000000000
class Vertice:
  def __init__(self, num):
    self.num = num
    self.connected = []
    self.edge = []
    self.pos = INF
    
def DFS(vertice):
  judge = True
  connected_num = len(vertice.connected)
  for i in range(connected_num):
    con = vertice.connected[i]
    if con.pos == INF:
      con.pos = vertice.pos + vertice.edge[i]
      judge = DFS(con)
    elif con.pos != vertice.pos + vertice.edge[i]:
      judge = False
    if judge == False:
      break
  return judge
 
N, M = map(int, input().split())
L, R, D = ([None for i in range(M)] for j in range(3))
vertices = [Vertice(i) for i in range(N)]
for i in range(M):
  L[i], R[i], D[i] = map(int, input().split())
for i in range(M):
  if not vertices[R[i] - 1] in vertices[L[i] - 1].connected:
    vertices[L[i] - 1].connected.append(vertices[R[i] - 1])
    vertices[R[i] - 1].connected.append(vertices[L[i] - 1])
    vertices[L[i] - 1].edge.append(D[i])
    vertices[R[i] - 1].edge.append(-D[i])
judge = True
for i in range(N):
  if vertices[i].pos == INF:
    vertices[i].pos = 0
    judge = DFS(vertices[i])
    if judge == False:
      break
if judge:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys                                                   
l1 = list(map(int, input().split()))                         
N = l1[0]                                                    
M = l1[1]                                                    
                                                             
dat = []                                                     
                                                             
per_dis = [ [] for n in range(N+1)]                          
                                                             
for n in range(M):                                           
    x = list(map(int, input().split()))                      
    dat.append(x)                                            
                                                             
def bfs(start, goal):                                        
    visited = []                                             
    unvisited = [(start, 0)]                                 
    while unvisited:                                         
        now = unvisited[0]                                   
        unvisited = unvisited[1:]                            
        for next in per_dis[now[0]]:                         
            if next[0] not in visited:                       
                if next[0] == goal:                          
                    return now[1] + next[1]                  
                unvisited.append((next[0], now[1] + next[1]))
                visited.append(now[0])                       
    return None                                              
                                                             
for x in dat:                                                
    tmp = bfs(x[0], x[1])                                    
    if None == tmp:                                          
        per_dis[x[0]].append((x[1],x[2]))                    
        per_dis[x[1]].append((x[0],-x[2]))                   
    elif  x[2] != tmp:                                       
        print("No")                                          
        break;                                               
else:                                                        
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys                                                   
l1 = list(map(int, input().split()))                         
N = l1[0]                                                    
M = l1[1]                                                    
                                                             
dat = []                                                     
                                                             
per_dis = [ [] for n in range(N+1)]                          
                                                             
for n in range(M):                                           
    x = list(map(int, input().split()))                      
    dat.append(x)                                            
                                                             
def bfs(start, goal):                                        
    visited = []                                             
    unvisited = [(start, 0)]                                 
    while unvisited:                                         
        now = unvisited[0]                                   
        unvisited = unvisited[1:]                            
        for next in per_dis[now[0]]:                         
            if next[0] not in visited:                       
                if next[0] == goal:                          
                    return now[1] + next[1]                  
                unvisited.append((next[0], now[1] + next[1]))
                visited.append(next[0])                      
    return None                                              
                                                             
for x in dat:                                                
    tmp = bfs(x[0], x[1])                                    
    if None == tmp:                                          
        per_dis[x[0]].append((x[1],x[2]))                    
        per_dis[x[1]].append((x[0],-x[2]))                   
    elif  x[2] != tmp:                                       
        print("No")                                          
        break;                                               
else:                                                        
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys                                                   
l1 = list(map(int, input().split()))                         
N = l1[0]                                                    
M = l1[1]                                                    
                                                             
dat = []                                                     
                                                             
per_dis = [ [] for n in range(N+1)]                          
                                                             
for n in range(M):                                           
    x = list(map(int, input().split()))                      
    dat.append(x)                                            
                                                             
def bfs(start, goal):                                        
    visited = []                                             
    unvisited = [(start, 0)]                                 
    while unvisited:                                         
        now = unvisited[0]                                   
        unvisited = unvisited[1:]                            
        for next in per_dis[now[0]]:                         
            if next[0] not in visited:                       
                if next[0] == goal:                          
                    return now[1] + next[1]                  
                unvisited.append((next[0], now[1] + next[1]))
                visited.append(next[0])                      
    return None                                              
                                                             
for x in dat:                                                
    if None == bfs(x[0], x[1]):                              
        per_dis[x[0]].append((x[1],x[2]))                    
        per_dis[x[1]].append((x[0],-x[2]))                   
    elif  x[2] != bfs(x[0], x[1]):                           
        print("No")                                          
        break;                                               
else:                                                        
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys                                                   
l1 = list(map(int, input().split()))                         
N = l1[0]                                                    
M = l1[1]                                                    
                                                             
dat = []                                                     
                                                             
per_dis = [ [] for n in range(N+1)]                          
                                                             
for n in range(M):                                           
    x = list(map(int, input().split()))                      
    dat.append(x)                                            
                                                             
def bfs(start, goal):                                        
    visited = []                                             
    unvisited = [(start, 0)]                                 
    while unvisited:                                         
        now = unvisited[0]                                   
        unvisited = unvisited[1:]                            
        for next in per_dis[now[0]]:                         
            if next[0] not in visited:                       
                if next[0] == goal:                          
                    return now[1] + next[1]                  
                unvisited.append((next[0], now[1] + next[1]))
                visited.append(next[0])                      
    return None                                              
                                                             
for x in dat:                                                
    res = bfs(x[0], x[1])                                    
    if None == res:                                          
        per_dis[x[0]].append((x[1],x[2]))                    
        per_dis[x[1]].append((x[0],-x[2]))                   
    elif  x[2] != res:                                       
        print("No")                                          
        sys.exit(0)                                          
                                                             
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys                                                    
l1 = list(map(int, input().split()))                          
N = l1[0]                                                     
M = l1[1]                                                     
                                                              
dat = []                                                      
                                                              
#per_dis = [[ 0 for n in range(N+1)] for n in range(N+1)]     
                                                              
per_dis = [ [] for n in range(N+1)]                           
                                                              
for n in range(M):                                            
    x = list(map(int, input().split()))                       
    dat.append(x)                                             
                                                              
def bfs(start, goal):                                         
    visited = []                                              
    unvisited = [(start, 0)]                                  
    while unvisited:                                          
        now = unvisited[0]                                    
        unvisited = unvisited[1:]                             
        for next in per_dis[now[0]]:                          
            if next[0] not in visited:                        
                if next[0] == goal:                           
                    return now[1] + next[1]                   
                unvisited.append((next[0], now[1] + next[1])) 
                visited.append(next[0])                       
    return None                                               
                                                              
for x in dat:                                                 
    if None == bfs(x[0], x[1]):                               
        per_dis[x[0]].append((x[1],x[2]))                     
        per_dis[x[1]].append((x[0],-x[2]))                    
    elif  x[2] != bfs(x[0], x[1]):                            
        print("No")                                           
        sys.exit(0)
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
def work():

    proceed=1

    while proceed>0:
       proceed=0
       for i in range(m):
          if ((pos[d[i][0]]<>-1) and (pos[d[i][1]]<>-1)):
              if (pos[d[i][1]]<>pos[d[i][0]]+d[i][2]) :return "No"
          else:
              if (pos[d[i][0]]<>-1):
                  pos[d[i][1]]=pos[d[i][0]]+d[i][2]
                  proceed=proceed+1
              if (pos[d[i][1]]<>-1):
                  pos[d[i][0]]=pos[d[i][1]]-d[i][2]
                  proceed=proceed+1

    return "Yes"


def judgeset():

    w=True

    for i in range(m):
        if pos[d[i][0]]==-1 :
            pos[d[i][0]]=0
            pos[d[i][1]]=d[i][2]
            w=False
            break
    return w





n,m = map(int, raw_input().split())
d=[]
for i in range(m):
   w = map(int, raw_input().split())
   d.append(w)

pos=[-1]*(n+1)


while True:
    if judgeset()==True :
        print "Yes"
        break
    if work()=="No" :
        print "No"
        break

Submission status: Time Limit Exceeded

Solution code:
def work():

    proceed=1

    while proceed>0:
       proceed=0
       for i in range(m):
          if ((pos[d[i][0]]<>-1) and (pos[d[i][1]]<>-1)):
              if (pos[d[i][1]]<>pos[d[i][0]]+d[i][2]) :return "No"
          if ((pos[d[i][0]]<>-1) and (pos[d[i][1]]==-1)):
              pos[d[i][1]]=pos[d[i][0]]+d[i][2]
              proceed=proceed+1
          if ((pos[d[i][0]]==-1) and (pos[d[i][1]]<>-1)):
              pos[d[i][0]]=pos[d[i][1]]-d[i][2]
              proceed=proceed+1

    return "Yes"


def judgeset():

    w=True

    for i in range(m):
        if pos[d[i][0]]==-1 :
            pos[d[i][0]]=0
            pos[d[i][1]]=d[i][2]
            w=False
            break
    return w





n,m = map(int, raw_input().split())
d=[]
for i in range(m):
   w = map(int, raw_input().split())
   d.append(w)

pos=[-1]*(n+1)


while True:
    if judgeset()==True :
        print "Yes"
        break
    if work()=="No" :
        print "No"
        break