Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
l = 0
while d:
    for i, k in enumerate(p[1:]):
        if con[i]!=0:continue
        if d[0] in k:
            d.append(i+2)
            con[i] = d[l]
    if len(d) > 1:
        d.pop(0)
    else:
        break
print('Yes')
for i in range(n-1):
    print(con[i])

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
l = 0
for _ in range(1, n):
    for i, k in enumerate(p[1:]):
        if con[i]!=0:continue
        if d[l] in k:
            d.append(i+2)
            con[i] = d[l]
    if len(d) > l:
        l += 1
    else:
        break
print('Yes')
for i in range(n-1):
    print(con[i])

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = {}
l = 0
for _ in range(1, n):
    for i, k in enumerate(p[1:]):
        if i+2 in d:continue
        if d[l] in k:
            d.append(i+2)
            con[i+2] = d[l]
    if len(d) > l:
        l += 1
    else:
        break
if len(con) < n-1:
    print('No')
else:
    print('Yes')
    for i in range(n-1):
        print(con[i+2])

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p1 = []
p2 = []
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p1.append(a)
    p2.append(b)
d = [1, ]
c = [0, ]
l = 0
flag = True
for _ in range(1, n):
    for i in range(m):
        if p1[i] == d[l]:
            d.append(p2[i])
            c.append(p1[i])
        if p2[i] == d[l]:
            d.append(p1[i])
            c.append(p2[i])
    if len(d) > l:
        l += 1
    else:
        flag = False
        break
con = []
for i in range(2, n+1):
    for y, j in enumerate(d):
        flfl = True
        if j == i:
            con.append(c[y])
            flfl=False
            break
    if flfl:
        con.append(0)
        break

if 0 in con:
    print('No')
else:
    print('Yes')
    for i in con:
        print(i)

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p1 = []
p2 = []
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p1.append(a)
    p2.append(b)
d = [1, ]
c = [0, ]
l = 0
flag = True
for j in range(1, n):
    for i, t in enumerate(p1):
        if t == d[l]:
            d.append(p2[i])
            c.append(t)
    for i, t in enumerate(p2):
        if t == d[l]:
            d.append(p1[i])
            c.append(t)
    if len(d) > l:
        l += 1
    else:
        flag = False
        break
con = []
for i in range(2, n+1):
    for y, j in enumerate(d):
        flfl = True
        if j == i:
            con.append(c[y])
            flfl=False
            break
        if not flfl:
            break
    if flfl:
        con.append(0)
        break

if 0 in con:
    print('No')
else:
    print('Yes')
    for i in con:
        print(i)


Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p1 = []
p2 = []
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p1.append(a)
    p2.append(b)
d = [[1], ]
c = [[0], ]
l = 0
flag = True
for j in range(1, n):
    a = []
    b = []
    for i, t in enumerate(p1):
        for h in d[l]:
            if t == h:
                a.append(p2[i])
                b.append(t)
    for i, t in enumerate(p2):
        for h in d[l]:
            if t == h:
                a.append(p1[i])
                b.append(t)
    d.append(a)
    c.append(b)
    if len(d) > l:
        l += 1
    else:
        flag = False
        break
con = []
for i in range(2, n+1):
    for y, j in enumerate(d):
        flfl = True
        if i in j:
            for w, k in enumerate(j):
                if k == i:
                    con.append(c[y][w])
                    flfl=False
                    break
        if not flfl:
            break
    if flfl:
        con.append(0)
        break

if 0 in con:
    print('No')
else:
    print('Yes')
    for i in con:
        print(i)

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])

Buggy python submission (verdict: Time Limit Exceeded):
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p1 = []
p2 = []
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p1.append(a)
    p2.append(b)
d = [[1], ]
c = [[0], ]
l = 0
flag = True
for j in range(1, n):
    a = []
    b = []
    for i, t in enumerate(p1):
        for h in d[l]:
            if t == h:
                a.append(p2[i])
                b.append(t)
    for i, t in enumerate(p2):
        for h in d[l]:
            if t == h:
                a.append(p1[i])
                b.append(t)
    d.append(a)
    c.append(b)
    if len(d) > l:
        l += 1
    else:
        flag = False
        break
con = []
for i in range(2, n+1):
    for y, j in enumerate(d):
        flfl = True
        for w, k in enumerate(j):
            if k == i:
                con.append(c[y][w])
                flfl=False
                break
        if not flfl:
            break
    if flfl:
        con.append(0)

if 0 in con:
    print('No')
else:
    print('Yes')
    for i in con:
        print(i)

Fixed submission:
it = input()
it = it.split()
n = int(it[0])
m = int(it[1])
p = [[] for _ in range(n)]
for _ in range(m):
    itf = input()
    itf = itf.split()
    a = int(itf[0])
    b = int(itf[1])
    p[a-1].append(b)
    p[b-1].append(a)
d = [1, ]
con = [0] * n
while d:
    l = d.pop(0)
    for k in p[l-1]:
        if con[k-2]==0:
            d.append(k)
            con[k-2] = l
print('Yes')
for i in range(n-1):
    print(con[i])