Buggy python submission (verdict: Time Limit Exceeded):
newarr = input()
newarr = newarr.split()
n = int(newarr[0])
m = int(newarr[1])
dicts = {}
ans = [0] * (n + 1)
for line in range(m):
    newarr = input()
    newarr = newarr.split()
    froom = int(newarr[0])
    sroom = int(newarr[1])
    if froom not in dicts:
        dicts[froom] = []
    if sroom not in dicts:
        dicts[sroom] = []
    dicts[froom].append(sroom)
    dicts[sroom].append(froom)
queue = []
if 1 not in dicts:
    print("No")
else:
    ans[1] = 1
    curarr = dicts[1]
    for i in curarr:
        queue.append(i)
        ans[i] = 1 
    while queue:
        curitem = queue.pop(0)
        if curitem not in dicts:
            continue 
        curarr = dicts[curitem]
        for i in curarr:
            if ans[i] == 0:
                ans[i] = curitem 
                queue.append(i)

    finalans = []
    flag = 0 
    for i in range(2, n + 1):
        if i == 0 :
            flag = 1 
            break 
        finalans.append(ans[i])
    if flag == 1:
        print("No")
    else:
        print("Yes")
        for i in finalans:
            print(i)




Fixed submission:
from collections import deque
newarr = input()
newarr = newarr.split()
n = int(newarr[0])
m = int(newarr[1])
dicts = {}
ans = [0] * (n + 1)
for line in range(m):
    newarr = input()
    newarr = newarr.split()
    froom = int(newarr[0])
    sroom = int(newarr[1])
    if froom not in dicts:
        dicts[froom] = []
    if sroom not in dicts:
        dicts[sroom] = []
    dicts[froom].append(sroom)
    dicts[sroom].append(froom)
queue = deque([])
if 1 not in dicts:
    print("No")
else:
    ans[1] = 1
    curarr = dicts[1]
    for i in curarr:
        queue.append(i)
        ans[i] = 1 
    while queue:
        curitem = queue.popleft()
        if curitem not in dicts:
            continue 
        curarr = dicts[curitem]
        for i in curarr:
            if ans[i] == 0:
                ans[i] = curitem 
                queue.append(i)

    finalans = []
    flag = 0 
    for i in range(2, n + 1):
        if i == 0 :
            flag = 1 
            break 
        finalans.append(ans[i])
    if flag == 1:
        print("No")
    else:
        print("Yes")
        for i in finalans:
            print(i)

Buggy python submission (verdict: Time Limit Exceeded):
temp = input()
temp = temp.split()
room = int(temp[0])
passage = int(temp[1])
adjlist = {}
visited = [0] * (room + 1) 
finalans = []
finalans.append(0)
findmin1 = {}
for i in range(passage):
    inpu = input()
    inpu = inpu.split()
    firstnode = int(inpu[0])
    secnode = int(inpu[1])
    if firstnode == 1:
        findmin1[secnode] = 1 
    if secnode == 1 :
        findmin1[firstnode] = 1 
    
    if firstnode not in adjlist:
        adjlist[firstnode] = []
    if secnode not in adjlist:
        adjlist[secnode] = []
        
    adjlist[firstnode].append(secnode)
    adjlist[secnode].append(firstnode)

flag = 0 
for i in range(2, room + 1):
    temparr = []
    ans = -1 
    visited = [0] * (room + 1) 
    if i not in adjlist:
        flag = 1 
        break
    templist = adjlist[i]
    if i in findmin1:
        finalans.append(1)
        continue 
    for j in templist:
        visited[j] = 1
        temparr.append((j, j))
    while True:
        if len(temparr) == 0:
            break
        getans = 0 
        newarr = []
        for node in temparr:
            newnode = node[0]
            firstnode = node[1]
            if newnode not in adjlist:
                continue 
            if newnode in findmin1:
                getans = 1 
                ans = firstnode
                break
            for j in adjlist[newnode]:
                if visited[j] == 1 :
                    continue 
                visited[j] = 1 
                newarr.append((j, firstnode))
        
        if getans == 1:
            break
        
        temparr = newarr[::]
    
    if ans == -1:
        flag = 1 
        break
    finalans.append(ans)

if flag == 1:
    print("No")
#print(adjlist)
else:
    print("Yes")
    for i,j in enumerate(finalans):
        if i == 0 :
            continue 
        print(j)
#print(finalans)

Fixed submission:
from collections import deque
newarr = input()
newarr = newarr.split()
n = int(newarr[0])
m = int(newarr[1])
dicts = {}
ans = [0] * (n + 1)
for line in range(m):
    newarr = input()
    newarr = newarr.split()
    froom = int(newarr[0])
    sroom = int(newarr[1])
    if froom not in dicts:
        dicts[froom] = []
    if sroom not in dicts:
        dicts[sroom] = []
    dicts[froom].append(sroom)
    dicts[sroom].append(froom)
queue = deque([])
if 1 not in dicts:
    print("No")
else:
    ans[1] = 1
    curarr = dicts[1]
    for i in curarr:
        queue.append(i)
        ans[i] = 1 
    while queue:
        curitem = queue.popleft()
        if curitem not in dicts:
            continue 
        curarr = dicts[curitem]
        for i in curarr:
            if ans[i] == 0:
                ans[i] = curitem 
                queue.append(i)

    finalans = []
    flag = 0 
    for i in range(2, n + 1):
        if i == 0 :
            flag = 1 
            break 
        finalans.append(ans[i])
    if flag == 1:
        print("No")
    else:
        print("Yes")
        for i in finalans:
            print(i)

Buggy python submission (verdict: Time Limit Exceeded):
temp = input()
temp = temp.split()
room = int(temp[0])
passage = int(temp[1])
adjlist = {}
visited = [0] * (room + 1) 
finalans = []
finalans.append(0)
for i in range(passage):
    inpu = input()
    inpu = inpu.split()
    firstnode = int(inpu[0])
    secnode = int(inpu[1])
    if firstnode not in adjlist:
        adjlist[firstnode] = []
    if secnode not in adjlist:
        adjlist[secnode] = []
        
    adjlist[firstnode].append(secnode)
    adjlist[secnode].append(firstnode)

flag = 0 
for i in range(2, room + 1):
    temparr = []
    ans = -1 
    visited = [0] * (room + 1) 
    if i not in adjlist:
        flag = 1 
        break
    templist = adjlist[i]
    if 1 in templist:
        finalans.append(1)
        continue 
    for j in templist:
        visited[j] = 1
        temparr.append((j, j))
    while True:
        if len(temparr) == 0:
            break
        getans = 0 
        newarr = []
        for node in temparr:
            newnode = node[0]
            firstnode = node[1]
            if newnode not in adjlist:
                continue 
            if 1 in adjlist[newnode] :
                getans = 1 
                ans = firstnode
                break
            for j in adjlist[newnode]:
                if visited[j] == 1 :
                    continue 
                visited[j] = 1 
                newarr.append((j, firstnode))
        
        if getans == 1:
            break
        
        temparr = newarr[::]
    
    if ans == -1:
        flag = 1 
        break
    finalans.append(ans)

if flag == 1:
    print("No")
#print(adjlist)
else:
    print("Yes")
    for i,j in enumerate(finalans):
        if i == 0 :
            continue 
        print(j)
#print(finalans)

Fixed submission:
from collections import deque
newarr = input()
newarr = newarr.split()
n = int(newarr[0])
m = int(newarr[1])
dicts = {}
ans = [0] * (n + 1)
for line in range(m):
    newarr = input()
    newarr = newarr.split()
    froom = int(newarr[0])
    sroom = int(newarr[1])
    if froom not in dicts:
        dicts[froom] = []
    if sroom not in dicts:
        dicts[sroom] = []
    dicts[froom].append(sroom)
    dicts[sroom].append(froom)
queue = deque([])
if 1 not in dicts:
    print("No")
else:
    ans[1] = 1
    curarr = dicts[1]
    for i in curarr:
        queue.append(i)
        ans[i] = 1 
    while queue:
        curitem = queue.popleft()
        if curitem not in dicts:
            continue 
        curarr = dicts[curitem]
        for i in curarr:
            if ans[i] == 0:
                ans[i] = curitem 
                queue.append(i)

    finalans = []
    flag = 0 
    for i in range(2, n + 1):
        if i == 0 :
            flag = 1 
            break 
        finalans.append(ans[i])
    if flag == 1:
        print("No")
    else:
        print("Yes")
        for i in finalans:
            print(i)