Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
depth = [[1]]
i = 0
co = 1
se = set(depth[0])
while co < n:
    te = [k for j in depth[i] for k in c[j]]
    te = set(te) - se
    if len(te) == 0:
        break
    co += len(te)
    se = te | se
    depth.append(list(te))
    i += 1

    
if co != n:
    print("No")
else:
    print("Yes")
    for i in range(1, len(depth)):
        te = depth[i-1]
        for j in depth[i]:
            t = c[j]
            for k in te:
                if k in t:
                    lis[j] = k
                    break
    print("\n".join(map(str, lis[2:])))

Fixed submission:
from collections import deque
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
    
que = deque([1])
check = [0 for i in range(n+1)]
check[1] = 1
while que:
    now = que.popleft()
    nx = c[now]
    for i in nx:
        if check[i] == 1:
            continue
        check[i] = 1
        lis[i] = now
        que.append(i)
if 0 in lis[2:]:
    print("No")
else:
    print("Yes")
    for i in lis[2:]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
depth = [[1]]
i = 0
co = 1
se = set(depth[0])
while co < n:
    te = [k for j in depth[i] for k in c[j]]
    te = set(te) - se
    if len(te) == 0:
        break
    co += len(te)
    se = te | se
    depth.append(list(te))
    i += 1

    
if co != n:
    print("No")
else:
    print("Yes")
    for i in range(1, len(depth)):
        te = depth[i-1]
        for j in depth[i]:
            t = c[j]
            for k in te:
                if k in t:
                    lis[j] = k
                    break
    print("\n".join(map(str, lis[2:])))

Fixed submission:
from collections import deque
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
    
que = deque([1])
check = [0 for i in range(n+1)]
check[1] = 1
while que:
    now = que.popleft()
    nx = c[now]
    for i in nx:
        if check[i] == 1:
            continue
        check[i] = 1
        lis[i] = now
        que.append(i)
if 0 in lis[2:]:
    print("No")
else:
    print("Yes")
    for i in lis[2:]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
def retrun_index(c_lis):
    return [i for i, x in enumerate(c_lis) if x==1]

n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a][b] = 1
    c[b][a] = 1
depth = [[1]]
i = 0
co = 1
se = set(depth[0])
while co < n:
    te = [k for j in depth[i] for k, x in enumerate(c[j]) if x==1]
    te = set(te) - se
    if len(te) == 0:
        break
    co += len(te)
    se = te | se
    depth.append(list(te))
    i += 1

    
if co != n:
    print("No")
else:
    print("Yes")
    for i in range(1, len(depth)):
        te = depth[i-1]
        for j in depth[i]:
            t = c[j]
            for k in te:
                if t[k]==1:
                    lis[j] = k
                    break
    for i in lis[2:]:
        print(i)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
    
que = deque([1])
check = [0 for i in range(n+1)]
check[1] = 1
while que:
    now = que.popleft()
    nx = c[now]
    for i in nx:
        if check[i] == 1:
            continue
        check[i] = 1
        lis[i] = now
        que.append(i)
if 0 in lis[2:]:
    print("No")
else:
    print("Yes")
    for i in lis[2:]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
def retrun_index(c_lis):
    return [i for i, x in enumerate(c_lis) if x==1]

n, m = map(int, input().split())
lis = [1, 1] + [0]*(n-1)
c = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a][b] = 1
    c[b][a] = 1
ind = retrun_index(c[1])
for i in ind:
    lis[i] = 1
i = 0
while True:
    if i>=len(ind):
        break
    t = ind[i]
    te = retrun_index(c[t])
    for j in te:
        if lis[j] == 0:
            lis[j] = t
            ind.append(j)
    i += 1

    
if lis.count(0) > 0:
    print("No")
else:
    print("Yes")
    for i in lis[2:]:
        print(i)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
lis = [0]*(n+1)
c = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    c[a].append(b)
    c[b].append(a)
    
que = deque([1])
check = [0 for i in range(n+1)]
check[1] = 1
while que:
    now = que.popleft()
    nx = c[now]
    for i in nx:
        if check[i] == 1:
            continue
        check[i] = 1
        lis[i] = now
        que.append(i)
if 0 in lis[2:]:
    print("No")
else:
    print("Yes")
    for i in lis[2:]:
        print(i)