Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    while len(q):
        now=q.popleft()
        seen[now]=True
        for i in graph[now]:
            if seen[i]:
                continue
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

Fixed submission:
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    seen[0]=True
    while len(q):
        now=q.popleft()
        for i in graph[now]:
            if seen[i]:
                continue
            seen[i]=True
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    while len(q):
        now=q.popleft()
        seen[now]=True
        for i in graph[now]:
            if seen[i]:
                continue
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

Fixed submission:
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    seen[0]=True
    while len(q):
        now=q.popleft()
        for i in graph[now]:
            if seen[i]:
                continue
            seen[i]=True
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

n,m=map(int,input().split())
graph=[[] for _ in range(n)]
seen=[False]*n

for _ in range(m):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
ans=[-1]*n
q=deque([0])
while len(q):
    now=q.popleft()
    seen[now]=True
    for i in graph[now]:
        if seen[i]:
            continue
        q.append(i)
        if ans[i]==-1:
            ans[i]=now
print("Yes")
for i in range(1,n):
    print(ans[i]+1)

Fixed submission:
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    seen[0]=True
    while len(q):
        now=q.popleft()
        for i in graph[now]:
            if seen[i]:
                continue
            seen[i]=True
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()