Buggy python submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.pop()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.append(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
now = {1}
itta = {1}
while len(now) > 0:
    next = set()
    for i in now:
        next = next | root[i]
    next -= itta
    for i in next:
        num = list(now & root[i])
        num = num[0]
        ans[i] = num
    itta = itta | next
    now = next
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = [1]
itta = {1}
while len(task) > 0:
    now = task[0]
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
    itta = itta | additional
    task = task[1:] + list(additional)
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
def cape(iri):
    ima = set()
    for i in iri:
        for j in root[i]:
            if ans[j] == 0:
                ans[j] = i
                root[j] -= iri #ここが重そう
                ima.add(j) #ここも重そう
    if len(ima) > 0:
        cape(ima)

N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
cape({1})
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
def cape(iri):
    ima = set()
    for i in iri:
        for j in root[i]:
            if ans[j] == 0:
 #               print("now", i, j, ima)
                ans[j] = i
 #               print(root[j])
                root[j] -= iri #ここが重そう
 #               print(root[j])
                ima.add(j) #ここも重そう
#                print(ima)
#    print(ima)
    if ima != set():
        cape(ima)

N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
#print(root)
cape({1})
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
import copy

def cape(iri):
    ima = set()
    for i in iri:
        for j in root[i]:
#            print(i, j)
            if ans[j] == 0:
                ans[j] = i
                root[j] -= {i}
                ima = ima | {j}
    if ima != set():
        cape(ima)

N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
#print(root)
cape({1})
#print(ans)
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])