Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[0 for i in range(n)]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1][b-1]=b-1
        r[b-1][a-1]=a-1
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            else:
                queue.append(i)
                visited[i]=True
                d[i]=now
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")


if __name__ == "__main__":
     main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[0 for i in range(n)]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1][b-1]=b-1
        r[b-1][a-1]=a-1
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if not visited[i]:
                queue.append(i)
                visited[i]=True
                d[i]=now
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")


if __name__ == "__main__":
     main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[0 for i in range(n)]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1][b-1]=b-1
        r[b-1][a-1]=a-1
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if not visited[i]:
                queue.append(i)
                visited[i]=True
                d[i]=now
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")


if __name__ == "__main__":
     main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[0 for i in range(n)]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1][b-1]=b-1
        r[b-1][a-1]=a-1
    #print(r)

    def bfs(n,r,start):
        #始点に対して終点"g"に着けるか判定
        from collections import deque
        d = [0 for i in range(n)]
        visited=[False for i in range(n)]
        flg = True
        queue=deque([0])
        dd=0
        while queue:
            now=queue.popleft()
            visited[now]=True
            #print(now)
            for i in r[now]:
                if not visited[i]:
                    queue.append(i)
                    visited[i]=True
                    d[i]=now
        #print(d)
        if flg:
            print("Yes")
            for i in range(1,n):
                print(d[i]+1)
        else:
            print("No")
        return
    bfs(n,r,start)

if __name__ == "__main__":
     main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n,m = map(int, input().split())
r=[[0 for i in range(n)]for i in range(n)]
start = [0, 0]
#print(bfs(h, w, m, start))
for i in range(m):
    a,b=map(int, input().split())
    r[a-1][b-1]=b-1
    r[b-1][a-1]=a-1
#print(r)

def bfs(n,r,start):
    #始点に対して終点"g"に着けるか判定

    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if not visited[i]:
                queue.append(i)
                visited[i]=True
                d[i]=now
    for i in range(n):
        if not visited:
            flg=False
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")
    return "Yes" if flg else "No"

bfs(n,r,start)
#print(d)
"""
    a = queue.Queue()
    a.put(start)
    while not a.empty():
        na, nb = map(int, a.get())
        if m[hh][ww] == "g":
            flg = True
            break

        for i in range(4):
            nx, ny = ww+dx[i], hh+dy[i]
            if 0 <= ny < h and 0 <= nx < w and m[ny][nx] != "#" and d[ny][nx] == 0:
                a.put([ny, nx])
                d[ny][nx] = 1
"""

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n,m = map(int, input().split())
r=[[0 for i in range(n)]for i in range(n)]
start = [0, 0]
#print(bfs(h, w, m, start))
for i in range(m):
    a,b=map(int, input().split())
    r[a-1][b-1]=b-1
    r[b-1][a-1]=a-1
#print(r)

def bfs(n,r,start):
    #始点に対して終点"g"に着けるか判定

    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if not visited[i]:
                queue.append(i)
                visited[i]=True
                d[i]=now
    for i in range(n):
        if not visited:
            flg=False
    #print(d)
    if flg:
        print("Yes")
        for i in range(1,n):
            print(d[i]+1)
    else:
        print("No")
    return "Yes" if flg else "No"

bfs(n,r,start)
#print(d)
"""
    a = queue.Queue()
    a.put(start)
    while not a.empty():
        na, nb = map(int, a.get())
        if m[hh][ww] == "g":
            flg = True
            break

        for i in range(4):
            nx, ny = ww+dx[i], hh+dy[i]
            if 0 <= ny < h and 0 <= nx < w and m[ny][nx] != "#" and d[ny][nx] == 0:
                a.put([ny, nx])
                d[ny][nx] = 1
"""

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

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


if __name__ == "__main__":
     main()