Problem p02678 (python)

Fixed submission:
n,m = map(int,input().split())
visited = [-1 for _ in range(n+1)]
visited[1] = 0
will = []
root = [[] for _ in range(n+1)] 
for i in range(m):
    a,b = map(int,input().split())
    root[a].append(b)
    root[b].append(a)

will.append(1)

while will:
    visit = will.pop(0)
    for i in root[visit]:
        if visited[i] != -1:
            continue
        will.append(i)
        visited[i] = visit

if visited[1:] == -1:
    print('No')
else:
    print('Yes')
    for i in range(2,len(visited)):
        print(visited[i])

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N,N), dtype='int8')

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N, N), dtype=int)

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N, N))

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N, N))

for i in range(0, M):
	A,B = map(int,input().split())
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
vector = np.zeros((N, N))

for i in range(0, M):
	A,B = map(int,input().split())
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))
que = [0]

while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)

if 0 in depth[:,1:][0]:
	print("No")
else:
	print("Yes")
	for dep in depth[:,1:][0]:
		print(np.where(depth==dep-1)[1][0]+1)

Buggy submission (verdict: Runtime Error):
import numpy as np

N,M = map(int,input().split())
inputs.pop(0)
vector = np.zeros((N, N))

for i in range(0, M):
	A,B = map(int,input().split())
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))
que = [0]

while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)

if 0 in depth[:,1:][0]:
	print("No")
else:
	print("Yes")
	for dep in depth[:,1:][0]:
		print(np.where(depth==dep-1)[1][0]+1)

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
import numpy as np

head = input().split()

N = int(head[0])
M = int(head[1])
inputs = [input() for i in range(M)]

vector = np.zeros((N, N))
for i in range(0, M):
	param = inputs[i].split()
	A = int(param[0])
	B = int(param[1])
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))
que = [0]

try:
  while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)
except Exception as e:
  print("No")
  return 0

if 0 in depth[:,1:][0]:
	print("No")
else:
	print("Yes")
	for dep in depth[:,1:][0]:
		print(np.where(depth==dep-1)[1][0]+1)

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
import numpy as np

head = input().split()

N = int(head[0])
M = int(head[1])
inputs = [input() for i in range(M)]

vector = np.zeros((N, N))
for i in range(0, M):
	param = inputs[i].split()
	A = int(param[0])
	B = int(param[1])
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))
que = [0]

while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)

if 0 in depth[:,1:][0]:
	print("No")
else:
	print("Yes")
	for dep in depth[:,1:][0]:
		print(np.where(depth==dep-1)[1][0]+1)

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
import numpy as np

head = input().split()

N = int(head[0])
M = int(head[1])
inputs = [input() for i in range(M)]

vector = np.zeros((N, N))
for i in range(0, M):
	param = inputs[i].split()
	A = int(param[0])
	B = int(param[1])
	vector[A-1:A,B-1:B] = 1
	vector[B-1:B,A-1:A] = 1

depth = np.zeros((1, N))
que = [0]

while not que == []:
	room = que[0]
	que.pop(0)
	search = np.where(vector[room:room+1]==1)[1]
	for next_room in search:
		if not depth[:,next_room:next_room+1] == 0 or next_room == 0:
			continue
		depth[:,next_room:next_room+1] = depth[:,room:room+1]+1
		que.append(next_room)

print("Yes")
for dep in depth[:,1:][0]:
	print(np.where(depth==dep-1)[1][0]+1)

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt

inputs = input()
inputs = inputs.split('\\n')

N = int(inputs[0].split()[0])
M = int(inputs[0].split()[1])

i = 1
dic = {}
for i in range(1, M+1):
#	print("探索%d回目" % i)
	param = inputs[i].split()
	A = param[0]
	B = param[1]

	if A in dic.keys():
		dic[A].append(B)
	else:
		dic[A] = []
		dic[A].append(B)

	if B in dic.keys():
		dic[B].append(A)
	else:
		dic[B] = []
		dic[B].append(A)
	
depth = {'1': 0}
que = dic['1']
count=1

while not que == []:
	next_que = []
	for room in que:
		if room in depth.keys():
			continue

		depth[room] = count
		for next_room in dic[str(room)]:
			if not next_room in next_que:
				next_que.append(next_room)
	count += 1
	que = next_que

dist = {}
for i in range(2, N+1):
	for room, dep in depth.items():
		if depth[str(i)]-1 == dep:
			dist[str(i)] = room
			break

print("yes")
for opt in dist.items():
	print(opt[1])

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
import numpy as np
import pandas as pd

inputs = input()
inputs = inputs.split('\n')

N = int(inputs[0].split()[0])
M = int(inputs[0].split()[1])

i = 1
dic = {}
for i in range(1, M+1):
#	print("探索%d回目" % i)
	param = inputs[i].split()
	A = param[0]
	B = param[1]

	if A in dic.keys():
		dic[A].append(B)
	else:
		dic[A] = []
		dic[A].append(B)

	if B in dic.keys():
		dic[B].append(A)
	else:
		dic[B] = []
		dic[B].append(A)
	
depth = {'1': 0}
que = dic['1']
count=1

while not que == []:
	next_que = []
	for room in que:
		if room in depth.keys():
			continue

		depth[room] = count
		for next_room in dic[str(room)]:
			if not next_room in next_que:
				next_que.append(next_room)
	count += 1
	que = next_que

dist = {}
for i in range(2, N+1):
	for room, dep in depth.items():
		if depth[str(i)]-1 == dep:
			dist[str(i)] = room
			break

print("yes")
for opt in dist.items():
	print(opt[1])

Buggy submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
import numpy as np
import pandas as pd

inputs = input()
inputs = inputs.split('\n')

N = int(inputs[0].split()[0])
M = int(inputs[0].split()[1])

i = 1
dic = {}
for i in range(1, M+1):
#	print("探索%d回目" % i)
	param = inputs[i].split()
	A = param[0]
	B = param[1]

	if A in dic.keys():
		dic[A].append(B)
	else:
		dic[A] = []
		dic[A].append(B)

	if B in dic.keys():
		dic[B].append(A)
	else:
		dic[B] = []
		dic[B].append(A)
	
depth = {'1': 0}
que = dic['1']
count=1

while not que == []:
	next_que = []
	for room in que:
		if room in depth.keys():
			continue

		depth[room] = count
		for next_room in dic[str(room)]:
			if not next_room in next_que:
				next_que.append(next_room)
	count += 1
	que = next_que

dist = {}
for i in range(2, N+1):
	for room, dep in depth.items():
		if depth[str(i)]-1 == dep:
			dist[str(i)] = room
			break

print("yes")
for opt in dist.items():
	print(opt[1])