Buggy python submission (verdict: Runtime Error):

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
def func(node, num, li):
    for i in li:
        if num < n:
            if num < ans[i][0]:
                ans[i] = (num, node)
                func(i, num+1, table[i])
            # print(ans[2:])


# print(table)
for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

# print(table)


num = 1



func(1, num, table[1])
# print(ans[2:])
ans_ = []
for i in ans[2:]:
    ans_.append(i[1])
# print(ans_)
if 1e9 in ans_:
    print("No")
else:
    print("Yes")
    for i in ans_:
        print(i)


# print(table)


Fixed submission:
import queue

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
seen = [False for _ in range(n+1)]
seen[1] = True

for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

q = queue.Queue()

q.put((1, table[1]))
while(not q.empty()):
    element = q.get()
    for i in element[1]:
        if seen[i]:
            continue
        ans[i] = element[0]
        seen[i] = True
        q.put((i, table[i]))


if 1e9 in ans[2:]:
    print("No")
else:
    print("Yes")
    for i in ans[2:]:
        print(i)

Buggy python submission (verdict: Runtime Error):

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1+2)]
def func(node, num, li):
    for i in li:
        if num < ans[i][0]:
            ans[i] = (num, node)
            func(i, num+1, table[i])
        # print(ans[2:])


# print(table)
for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

# print(table)


num = 1



func(1, num, table[1])
# print(ans[2:])
ans_ = []
for i in ans[2:]:
    ans_.append(i[1])
# print(ans_)
if 1e9 in ans_:
    print("No")
else:
    print("Yes")
    for i in ans_:
        print(i)


# print(table)


Fixed submission:
import queue

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
seen = [False for _ in range(n+1)]
seen[1] = True

for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

q = queue.Queue()

q.put((1, table[1]))
while(not q.empty()):
    element = q.get()
    for i in element[1]:
        if seen[i]:
            continue
        ans[i] = element[0]
        seen[i] = True
        q.put((i, table[i]))


if 1e9 in ans[2:]:
    print("No")
else:
    print("Yes")
    for i in ans[2:]:
        print(i)

Buggy python submission (verdict: Runtime Error):

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
def func(node, num, li):
    for i in li:
        if num < ans[i][0]:
            ans[i] = (num, node)
            func(i, num+1, table[i])
        # print(ans[2:])


# print(table)
for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

# print(table)


num = 1



func(1, num, table[1])
# print(ans[2:])
ans_ = []
for i in ans[2:]:
    ans_.append(i[1])
# print(ans_)
if 1e9 in ans_:
    print("No")
else:
    print("Yes")
    for i in ans_:
        print(i)


# print(table)


Fixed submission:
import queue

n, m = map(int, input().split())
table = [[] for i in range(n+1)]
ans = [(1e9, 0) for i in range(n+1)]
seen = [False for _ in range(n+1)]
seen[1] = True

for i in range(m):
    a, b = map(int, input().split())
    # print(table[min(a, b)])
    # table[min(a, b)].append(max(a, b))
    table[a].append(b)
    table[b].append(a)

q = queue.Queue()

q.put((1, table[1]))
while(not q.empty()):
    element = q.get()
    for i in element[1]:
        if seen[i]:
            continue
        ans[i] = element[0]
        seen[i] = True
        q.put((i, table[i]))


if 1e9 in ans[2:]:
    print("No")
else:
    print("Yes")
    for i in ans[2:]:
        print(i)