Buggy python submission (verdict: Time Limit Exceeded):
import copy

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)
    
room = 1

deepList[room] = 0
deepSet = {0:{room}}
deep = 1
roomList = {room}
nextRoomlist = set()
count = 1

while count > 0:
    count = 0
    for room in roomList:
        for i in coriddorList[room]:
            if deepList[i] == -1:
                deepList[i] = deep
                nextRoomlist.add(i)
                count += 1
    roomList = copy.copy(nextRoomlist)
    deep += 1

deepList[0] = 0

for i in range(n+1):
    value = deepList[i]
    if value in deepSet.keys():
        deepSet[value].add(i)
    else:
        deepSet[value] = {i}

ansList = []

for i in range(2,n+1):
    deep = deepList[i]
    lis = coriddorList[i]
    for k in deepSet[deep - 1]:
        if k in lis:
            ansList.append(k)
            break

if -1 in deepList:
    print("No")
else:
    print("Yes")
    for i in range(len(ansList)):
        print(ansList[i])


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split()

n = int(s[0])
m = int(s[1])

ld = {}

for i in range(m):
    t = input().split()
    if int(t[0]) in ld:
       ld[int(t[0])].add(int(t[1]))
    else:
       ld[int(t[0])] = {int(t[1])}
    if int(t[1]) in ld:
        ld[int(t[1])].add(int(t[0]))
    else:
        ld[int(t[1])] = {int(t[0])}


if sum(ld.keys()) < int(((n + 1) * n ) / 2):
    print("No")
else:
    s1 = {1}
    s2 = set()
    count = 0
    mydict = {}

    while len(ld) > 0:
        s2.clear()
        for i in ld:
            if len(s1 & ld[i]) != 0:
                #s3 = list(s1 & ld[i])
                mydict.setdefault(i,list(s1 & ld[i])[0])
                s2.add(i)
        for i in s2:
            del ld[i]
        s1 = s2.copy()

    print("Yes")
    for i in range(2,n+1):
        print(mydict[i])


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Runtime Error):
s = input().split()

n = int(s[0])
m = int(s[1])

ld = {}
root = []

for i in range(m):
    t = input().split()
    if int(t[0]) in ld:
       ld[int(t[0])].add(int(t[1]))
    else:
       ld[int(t[0])] = {int(t[1])}
    if int(t[1]) in ld:
        ld[int(t[1])].add(int(t[0]))
    else:
        ld[int(t[1])] = {int(t[0])}
    root.append({int(t[0]),int(t[1])})


if sum(ld.keys()) < int(((n + 1) * n ) / 2):
    print("No")
else:
    goal = [1]
    result = {}

    for i in range(n):
        count = 0
        for j in range(m-len(goal)):
            if goal[i] in root[j-count]:
                result[int(list(root[j-count] - {goal[i]})[0])] = goal[i]
                goal.append(int(list(root[j-count] - {goal[i]})[0]))
                #print(root[j-count])
                del root[j-count]
                count += 1
        if len(goal) >= n:
            break

    print("Yes")
    for i in range(2,n+1):
        print(result[i])

    #print(goal)
    #print(result)


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split()

n = int(s[0])
m = int(s[1])

ld = {}

for i in range(m):
    t = input().split()
    if int(t[0]) in ld:
        ld[int(t[0])].add(int(t[1]))
    else:
        ld[int(t[0])] = {int(t[1])}
    if int(t[1]) in ld:
        ld[int(t[1])].add(int(t[0]))
    else:
        ld[int(t[1])] = {int(t[0])}


if sum(ld.keys()) < int(((n + 1) * n ) / 2):
    print("No")
else:
    s1 = {1}
    s2 = set()
    count = 0
    mydict = {}

    while len(ld) > 0:
        s2.clear()
        for i in ld:
            if len(s1 & ld[i]) != 0:
                #s3 = list(s1 & ld[i])
                mydict.setdefault(i,list(s1 & ld[i])[0])
                s2.add(i)
        for i in s2:
            del ld[i]
        s1 = s2.copy()

    print("Yes")
    for i in range(2,n+1):
        print(mydict[i])


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split()

n = int(s[0])
m = int(s[1])

sl = set()
ld = {}

s1 = {1}
s2 = set()


for i in range(m):
    t = input().split()
    sl.add(int(t[0]))
    sl.add(int(t[1]))
    if int(t[0]) in ld:
        ld[int(t[0])].add(int(t[1]))
    else:
        ld[int(t[0])] = {int(t[1])}
    if int(t[1]) in ld:
        ld[int(t[1])].add(int(t[0]))
    else:
        ld[int(t[1])] = {int(t[0])}


if sum(sl) < int(((n + 1) * n ) / 2):
    print("No")
else:
    count = 0
    mydict = {}

    while len(ld) > 0:
        s2.clear()
        for i in ld:
            if len(s1 & ld[i]) != 0:
                #s3 = list(s1 & ld[i])
                mydict.setdefault(i,list(s1 & ld[i])[0])
                s2.add(i)
        for i in s2:
            del ld[i]
        s1 = s2.copy()

    print("Yes")
    for i in range(2,n+1):
        print(mydict[i])

Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split()

n = int(s[0])
m = int(s[1])

#ll = [set() for j in range(n + 1)]
sl = set()
ld = {}

s1 = {1}
s2 = set()


for i in range(m):
    t = input().split()
    sl.add(int(t[0]))
    sl.add(int(t[1]))
    #ll[int(t[0])].add(int(t[1]))
    #ll[int(t[1])].add(int(t[0]))
    if int(t[0]) in ld:
        ld[int(t[0])].add(int(t[1]))
    else:
        ld[int(t[0])] = {int(t[1])}
    if int(t[1]) in ld:
        ld[int(t[1])].add(int(t[0]))
    else:
        ld[int(t[1])] = {int(t[0])}


if sum(sl) < int(((n + 1) * n ) / 2):
    print("No")
else:
    count = 0
    mydict = {}
    out = 0

    while count < n:
        s2.clear()
        for i in ld:
            if len(s1 & ld[i]) != 0:
                s3 = list(s1 & ld[i])
                mydict.setdefault(i,s3[0])
                s2.add(i)
                count += 1
        for i in s2:
            del ld[i]
        s1 = s2.copy()

    print("Yes")
    for i in range(2,n+1):
        print(mydict[i])


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().split()

n = int(s[0])
m = int(s[1])

ll = [set() for j in range(n + 1)]
sl = set()

s1 = {1}
s2 = set()


for i in range(m):
    t = input().split()
    sl.add(int(t[0]))
    sl.add(int(t[1]))
    ll[int(t[0])].add(int(t[1]))
    ll[int(t[1])].add(int(t[0]))


if sum(sl) < int(((n + 1) * n ) / 2):
    print("No")
else:
    count = 0
    mydict = {}
    out = 0

    while count < n:
        s2.clear()
        for i in sl:
            if len(s1 & ll[i]) != 0:
                s3 = list(s1 & ll[i])
                mydict.setdefault(i,s3[0])
                s2.add(i)
                count += 1
        sl = sl - s2
        s1 = s2.copy()

    print("Yes")
    for i in range(2,n+1):
        print(mydict[i])

Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = input().split()

n = int(s[0])
m = int(s[1])


ll = [set() for j in range(n + 1)]
sl = set()

s1 = {1}
s2 = set()


for i in range(m):
    t = input().split()
    sl.add(int(t[0]))
    sl.add(int(t[1]))
    ll[int(t[0])].add(int(t[1]))
    ll[int(t[1])].add(int(t[0]))


if sum(sl) < int(((n + 1) * n ) / 2):
    print("No")
    #print(sl,int(((n + 1) * n ) / 2))
else:
    count = 0
    goal = [0 for i in range(n)]
    out = 0

    while count < n:
        s2.clear()
        #out += 1
        for i in sl:
            if len(s1 & ll[i]) != 0:
                s3 = list(s1 & ll[i])
                #print(s3)
                goal[i-1] = s3[0]
                s2.add(i)
                count += 1
                #del ll[i]
                #ll[i].clear()
        sl = sl - s2
        s1 = s2.copy()
        #print(s1,s2)

        #if out >= 200:
        #    break
    print("Yes")
    for i in range(1,n):
        print(goal[i])

    #print(count,out)
    #print(goal)


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = input().split()

n = int(s[0])
m = int(s[1])


ll = [set() for j in range(n + 1)]
sl = set()

s1 = {1}
s2 = set()


for i in range(m):
    t = input().split()
    sl.add(int(t[0]))
    sl.add(int(t[1]))
    ll[int(t[0])].add(int(t[1]))
    ll[int(t[1])].add(int(t[0]))


if sum(sl) < int(((n + 1) * n ) / 2):
    print("No")
    #print(sl,int(((n + 1) * n ) / 2))
else:
    count = 0
    goal = [0 for i in range(n)]
    out = 0

    while 1:
        s2.clear()
        out += 1
        for i in range(1,n+1):
            if len(s1 & ll[i]) != 0:
                s3 = list(s1 & ll[i])
                #print(s3)
                goal[i-1] = s3[0]
                s2.add(i)
                count += 1
                ll[i].clear()
        s1 = copy.deepcopy(s2)
        #print(s1,s2)

        if out >= 2000 or count >= n:
            break
    print("Yes")
    for i in range(1,n):
        print(goal[i])

    #print(count,out)
    #print(goal)


Fixed submission:
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])