from collections import deque



mi = lambda:list(map(int,input().split()))

mix = lambda x:list(mi() for _ in range(x))

##########

def main(n,m,l):

    #グラフの作成

    g = creategraph(n,l)

    #独立した部屋がある場合はNG

    for i in range(1,len(g)):

        if len(g[i]) == 0:

            print("No")

            return

    #BFSで道標を作成

    navi = bfs(n,g)

    #部屋1を除く部屋の道標が更新されていなければNG

    if min(navi[2:]) == 0:

        print("No")

    else:

        print("Yes")

        for i in navi[2:]:

            print(i)



#BFS幅優先探索

def bfs(n,g):

    navi = [0]*(n+1)

    navi[1] = -1

    q = deque()

    q.append(1)

    while len(q) > 0:

        #キューから現在地を取り出す

        cp = q.popleft()

        #現在地の隣接点リストを取得

        np = g[cp]

        #隣接点が未探索ならキューに入れる＋道標更新

        for i in np:

            if navi[i] == 0:

                navi[i] = cp

                q.append(i)

    return navi



#各Nodeの隣接点を保持するリストを生成する

def creategraph(n,l):

    g = {i:[] for i in range(n+1)}

    for a,b in l:

        g[a].append(b)

        g[b].append(a)

    return g



def resolve():

    n,m = mi()

    l = mix(m)

    main(n,m,l)



if __name__ == "__main__":

    resolve()
from collections import deque



N,M=list(map(int,input().split()))

graph=[[] for i in range(N+1)]

for i in range(M):

    A,B=list(map(int,input().split()))

    graph[A].append(B)

    graph[B].append(A)

dist=[-1]*(N+1)

dist[0]=0

dist[1]=0

d=deque()

d.append(1)

ans=[0]*(N+1)

while d:

    v=d.popleft()

    for i in graph[v]:

        if dist[i]!=-1:

            continue

        dist[i]=dist[v]+1

        d.append(i)

        if ans[i]!=0:

            continue

        ans[i]+=v

print("Yes")

for i in ans:

    if i==0:

        continue

    print(i)     







    



















        



    



















    



        









    































    







    











    













        













    

































        





















































            

    





    





    

    





























    





    

























from collections import deque

mi = lambda: list(map(int, input().split()))
mix = lambda x: list(mi() for _ in range(x))
##########
def main(n, m, l):
    # グラフの作成
    g = creategraph(n, l)
    # 独立した部屋がある場合はNG
    for i in range(1, len(g)):
        if len(g[i]) == 0:
            print("No")
            return
    # BFSで道標を作成
    navi = bfs(n, g)
    # 部屋1を除く部屋の道標が更新されていなければNG
    if min(navi[2:]) == 0:
        print("No")
    else:
        print("Yes")
        for i in navi[2:]:
            print(i)


# BFS幅優先探索
def bfs(n, g):
    navi = [0] * (n + 1)
    navi[1] = -1
    q = deque()
    q.append(1)
    while len(q) > 0:
        # キューから現在地を取り出す
        cp = q.popleft()
        # 現在地の隣接点リストを取得
        np = g[cp]
        # 隣接点が未探索ならキューに入れる＋道標更新
        for i in np:
            if navi[i] == 0:
                navi[i] = cp
                q.append(i)
    return navi


# 各Nodeの隣接点を保持するリストを生成する
def creategraph(n, l):
    g = {i: [] for i in range(n + 1)}
    for a, b in l:
        g[a].append(b)
        g[b].append(a)
    return g


def resolve():
    n, m = mi()
    l = mix(m)
    main(n, m, l)


if __name__ == "__main__":
    resolve()

from collections import deque

N, M = list(map(int, input().split()))
graph = [[] for i in range(N + 1)]
for i in range(M):
    A, B = list(map(int, input().split()))
    graph[A].append(B)
    graph[B].append(A)
dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0
d = deque()
d.append(1)
ans = [0] * (N + 1)
while d:
    v = d.popleft()
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)
        if ans[i] != 0:
            continue
        ans[i] += v
print("Yes")
for i in ans:
    if i == 0:
        continue
    print(i)

-mi = lambda: list(map(int, input().split())) -mix = lambda x: list(mi() for _ in range(x)) -########## -def main(n, m, l): -    # グラフの作成 -    g = creategraph(n, l) -    # 独立した部屋がある場合はNG -    for i in range(1, len(g)): -        if len(g[i]) == 0: -            print("No") -            return -    # BFSで道標を作成 -    navi = bfs(n, g) -    # 部屋1を除く部屋の道標が更新されていなければNG -    if min(navi[2:]) == 0: -        print("No") -    else: -        print("Yes") -        for i in navi[2:]: -            print(i) - - -# BFS幅優先探索 -def bfs(n, g): -    navi = [0] * (n + 1) -    navi[1] = -1 -    q = deque() -    q.append(1) -    while len(q) > 0: -        # キューから現在地を取り出す -        cp = q.popleft() -        # 現在地の隣接点リストを取得 -        np = g[cp] -        # 隣接点が未探索ならキューに入れる＋道標更新 -        for i in np: -            if navi[i] == 0: -                navi[i] = cp -                q.append(i) -    return navi - - -# 各Nodeの隣接点を保持するリストを生成する -def creategraph(n, l): -    g = {i: [] for i in range(n + 1)} -    for a, b in l: -        g[a].append(b) -        g[b].append(a) -    return g - - -def resolve(): -    n, m = mi() -    l = mix(m) -    main(n, m, l) - - -if __name__ == "__main__": -    resolve() +N, M = list(map(int, input().split())) +graph = [[] for i in range(N + 1)] +for i in range(M): +    A, B = list(map(int, input().split())) +    graph[A].append(B) +    graph[B].append(A) +dist = [-1] * (N + 1) +dist[0] = 0 +dist[1] = 0 +d = deque() +d.append(1) +ans = [0] * (N + 1) +while d: +    v = d.popleft() +    for i in graph[v]: +        if dist[i] != -1: +            continue +        dist[i] = dist[v] + 1 +        d.append(i) +        if ans[i] != 0: +            continue +        ans[i] += v +print("Yes") +for i in ans: +    if i == 0: +        continue +    print(i)