Buggy python submission (verdict: Time Limit Exceeded):
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

print("Yes")
for hoge in range(500000):
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
            dq.append(hoge)


    if(len(dq) == 0):
        break

for ans in ans_list[2:]:
    print(ans)    



Fixed submission:
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

print("Yes")
for hoge in range(500000):
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
            dq.append(hoge)


    if(len(dq) == 0):
        break

for ans in ans_list[2:]:
    print(ans)    



Fixed submission:
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

print("Yes")
for hoge in range(500000):
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
        dq.append(hoge)

    if(0 not in ans_list[2:]):
        break

for ans in ans_list[2:]:
    print(ans)    



Fixed submission:
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

for hoge in range(500000)
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
        dq.append(hoge)

    if(0 not in ans_list[2:]):
        break

for ans in ans_list[2:]:
    print(ans)    



Fixed submission:
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

print("Yes")
while 0 in ans_list[2:]:
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
        dq.append(hoge)

for ans in ans_list[2:]:
    print(ans)    



Fixed submission:
import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)