Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = set([])
prev_cnt = 0
now = [1]

while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    prev.add(n)
    elist = []
    for next in Edict[n]:
        if next not in now:
            if next not in prev:
                output[next] = n
                now.append(next)

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")




Fixed submission:
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = [0 for n in range(N+1)]
prev_cnt = 0
now = [1]

prev[1] = 1
while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for next in Edict[n]:
        if prev[next] == 0:
            output[next] = n
            now.append(next)
            prev[next] = 1

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append(set([a,b]))

# program
output = [0] + [0] + [BigM]*(N-1)
prev = set([])
prev_cnt = 0
now = [1]

while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    prev.add(n)
    elist = []
    for e in E:
        if n in e:
            elist.append(e)
    for e in elist:
        next = list(e - set([n]))[0]
        if next not in now:
            if next not in prev:
                output[next] = n
                now.append(next)
        E.remove(e)

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")




Fixed submission:
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = [0 for n in range(N+1)]
prev_cnt = 0
now = [1]

prev[1] = 1
while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for next in Edict[n]:
        if prev[next] == 0:
            output[next] = n
            now.append(next)
            prev[next] = 1

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append(set([a,b]))

output = [0] + [0] + [BigM]*(N-1)
prev = set([])
prev_cnt = 0
now = [1]

while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    prev.add(n)
    elist = []
    for e in E:
        if n in e:
            elist.append(e)
    for e in elist:
        next = list(e - set([n]))[0]
        if next not in now:
            if next not in prev:
                output[next] = n
                now.append(next)
                E.remove(e)

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")




Fixed submission:
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = [0 for n in range(N+1)]
prev_cnt = 0
now = [1]

prev[1] = 1
while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for next in Edict[n]:
        if prev[next] == 0:
            output[next] = n
            now.append(next)
            prev[next] = 1

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append(set([a,b]))

output = [0] + [0] + [BigM]*(N-1)
prev_cnt = 0
now = [1]

while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for e in E:
        if n in e:
            next = list(e - set([n]))[0]
            if output[next] == BigM:
                output[next] = n
                now.append(int(next))

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")




Fixed submission:
inp = input()
inp = inp.split()
N = int(inp[0])
M = int(inp[1])
BigM = N+2

E = []
for m in range(M):
    abinp = input()
    abinp = abinp.split()
    a = int(abinp[0])
    b = int(abinp[1])
    E.append([a,b])

# program
Edict = [[] for n in range(N+1)]
for e in E:
    Edict[e[0]].append(e[1])
    Edict[e[1]].append(e[0])

output = [0] + [0] + [BigM]*(N-1)
prev = [0 for n in range(N+1)]
prev_cnt = 0
now = [1]

prev[1] = 1
while len(now) > 0:
    n = now.pop(0)
    prev_cnt += 1
    for next in Edict[n]:
        if prev[next] == 0:
            output[next] = n
            now.append(next)
            prev[next] = 1

if prev_cnt == N:
    print("Yes")
    for n in range(2,N+1):
        print(output[n])
else:
    print("No")