Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

network = [[] for _ in range(N+1)]

res = np.zeros((N+1), dtype="int32")
distance = np.full((N+1), N+1)
distance[1] = 0


for _ in range(M):
    i, j = list(map(int, input().split()))
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    s.append(top)
    for i in network[top]:
        if i not in s:
            queue.append(i)
            if distance[i] > distance[top]+1:
                distance[i] = distance[top]+1
                res[i] = top

    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

Fixed submission:
import numpy as np

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

network = [[] for _ in range(N+1)]
res = [0 for _ in range(N+1)]
distance = [N+1 for _ in range(N+1)]
distance[1] = 0


for _ in range(M):
    i, j = map(int, input().split())
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    for i in network[top]:
        if distance[i] > distance[top]+1:
            distance[i] = distance[top]+1
            res[i] = top
            queue.append(i)
    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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


network = {}
for i in range(N+1):
    network[i] = list()
res = np.zeros((N+1), dtype="int32")
distance = np.full((N+1), N+1)
distance[1] = 0


for _ in range(M):
    i, j = list(map(int, input().split()))
    network[i].append(j)
    network[j].append(i)

s = []

from collections import deque


n = 0
queue = deque([1])
while n < N:
    top = queue.popleft()
    s.append(top)
    for i in network[top]:
        if i not in s:
            queue.append(i)
            if distance[i] > distance[top]+1:
                distance[i] = distance[top]+1
                res[i] = top

    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

Fixed submission:
import numpy as np

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

network = [[] for _ in range(N+1)]
res = [0 for _ in range(N+1)]
distance = [N+1 for _ in range(N+1)]
distance[1] = 0


for _ in range(M):
    i, j = map(int, input().split())
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    for i in network[top]:
        if distance[i] > distance[top]+1:
            distance[i] = distance[top]+1
            res[i] = top
            queue.append(i)
    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

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

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

mat = np.zeros((N,N))
res = np.zeros((N))
distance = np.full((N), N+1)
distance[0] = 0

for _ in range(M):
    i, j = list(map(int, input().split()))
    mat[i-1][j-1] = 1
    mat[j-1][i-1] = 1

print(mat)

for i in range(N):
    for j in range(N):
        if mat[i][j] == 1:
            print(i,j)
            new_d = distance[i] + 1
            if distance[j] > new_d:
                distance[j] = new_d
                res[j] = i+1
            
print(res[1:])

Fixed submission:
import numpy as np

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

network = [[] for _ in range(N+1)]
res = [0 for _ in range(N+1)]
distance = [N+1 for _ in range(N+1)]
distance[1] = 0


for _ in range(M):
    i, j = map(int, input().split())
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    for i in network[top]:
        if distance[i] > distance[top]+1:
            distance[i] = distance[top]+1
            res[i] = top
            queue.append(i)
    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

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

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

mat = np.zeros((N,N))
res = np.zeros((N))
distance = np.full((N), N+1)
distance[0] = 0

for _ in range(M):
    i, j = list(map(int, input().split()))
    mat[i-1][j-1] = 1
    mat[j-1][i-1] = 1


for i in range(N):
    for j in range(N):
        if mat[i][j] == 1:
            new_d = distance[i] + 1
            if distance[j] > new_d:
                distance[j] = new_d
                res[j] = i+1
            
print(res[1:])

Fixed submission:
import numpy as np

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

network = [[] for _ in range(N+1)]
res = [0 for _ in range(N+1)]
distance = [N+1 for _ in range(N+1)]
distance[1] = 0


for _ in range(M):
    i, j = map(int, input().split())
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    for i in network[top]:
        if distance[i] > distance[top]+1:
            distance[i] = distance[top]+1
            res[i] = top
            queue.append(i)
    n += 1


print("Yes")  
for r in res[2:]:
    print(r)