      MODULE intQueueMod
      implicit none
! Module for QUEUE : First in, First out
! reference : プログラミングコンテスト攻略のための
!              アルゴリズムとデータ構造

      integer(16),parameter :: binSize = 10**6
      integer(16),parameter :: precision = 16
      
      type intQueue
        private
        integer(precision) :: bin( 1:binSize ) = 0
        integer(precision) :: head = 1,   tail = 1
        !head : Where the head value is.
        !tail : Where the blank next to tail is.
        contains
        procedure,public,pass :: initialize => intInit
        procedure,public,pass :: isEmpty    => intIsEmpty
        procedure,public,pass :: isFull     => intIsFull
        procedure,public,pass :: enQueue    => intEnQ
        procedure,public,pass :: deQueue    => intDeQ
      end type
      
      contains
!Reset queue. Not nessesary in first time.
      pure subroutine intInit( q )
        implicit none
        class(intQueue),intent(inout) :: q
        
        q%head = 1
        q%tail = 1
      end subroutine intInit
      
!Check status
      pure function intIsEmpty( q ) result( ans )
        implicit none
        class(intQueue),intent(in) :: q
        logical :: ans
        
        ans = q%head==q%tail
      end function intIsEmpty
      
      
      pure function intIsFull( q ) result( ans )
        implicit none
        class(intQueue),intent(in) :: q
        logical :: ans
        
        ans = q%head==mod( q%tail+1,binSize )
      end function intIsFull

!set x to tail
      subroutine intEnQ( q,x )
        implicit none
        class(intQueue)      ,intent(inout) :: q
        integer(precision),intent(in   ) :: x
        
        if( q%isFull() )then
          print*,'Queue is full,Error!';stop
        else
          q%bin(q%tail) = x
          if( q%tail==binSize )then
            q%tail = 1
          else
            q%tail = q%tail + 1
          end if
        end if
      end subroutine intEnQ
      
!get x from head
      impure function intDeQ( q ) result( x )
        implicit none
        class(intQueue),intent(inout) :: q
        integer(precision) :: x
        
        if( q%isEmpty() )then
          print*,'Stack is empty, Error!';stop
        else
          x = q%bin(q%head)
          if( q%head==binSize )then
            q%head = 1
          else
            q%head = q%head + 1
          end if
        end if
      end function intDeQ
      END MODULE intQueueMod
      
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      module piyoMod
      use intQueueMod
      
      type rooms
        integer(16),allocatable :: nei(:)
        integer(16) :: numNei=0
      end type
      
      integer(16),allocatable :: flag(:)
      type(intQueue) :: nextQ,beforeQ
      
      contains
      subroutine solve( rIn,roomNum,before )
        implicit none
        type(rooms),intent(in),allocatable :: rIn(:)
        integer(16),intent(in) :: roomNum,before
        integer(16) :: i
        
        if( flag(roomNum)/=-1 ) return
        flag( roomNum ) = before
        if( rIn(roomNum)%numNei==0 ) return
        
        do i = 1,rIn(roomNum)%numNei
          call nextQ%enQueue( rIn(roomNum)%nei(i) )
          call beforeQ%enQueue( roomNum )
        end do
        
      end subroutine
      end module
      
      PROGRAM doubleDots
      use piyoMod
      IMPLICIT NONE
      integer(16) :: n,m,numNei,buffer(5*10**5+1)
      integer(16),allocatable :: a(:),b(:)
      type(rooms),allocatable :: room(:)
      integer(16) :: i
      
      read*,n,m
      allocate( a(m),b(m),room(n),flag(n) )
      flag(1:n) = -1
      do i = 1,m
        read*,a(i),b(i)
      end do
      
      do i = 1,m !このdoの中にTLE原因がある！！！！
        room(a(i))%numNei = room(a(i))%numNei + 1
        numNei = room(a(i))%numNei
        buffer(1:numNei-1) = room(a(i))%nei(1:numNei-1)
        if(allocated(room(a(i))%nei).and.size(room(a(i))%nei(:))<numNei )then
          deallocate( room(a(i))%nei )
          allocate( room(a(i))%nei(numNei*2) )
        end if
        buffer(numNei) = b(i)
        room(a(i))%nei(1:numNei) = buffer(1:numNei)
        
        room(b(i))%numNei = room(b(i))%numNei + 1
        numNei = room(b(i))%numNei
        buffer(1:numNei-1) = room(b(i))%nei(1:numNei-1)
        if(allocated(room(b(i))%nei).and.size(room(b(i))%nei(:))<numNei )then
          deallocate( room(b(i))%nei )
          allocate( room(b(i))%nei(numNei*2) )
        end if
        buffer(numNei) = a(i)
        room(b(i))%nei(1:numNei) = buffer(1:numNei)
      end do
      
      
      call nextQ%enQueue(1_16)
      call beforeQ%enQueue(0_16) !dummy
  !    do while( .true. )
  !      if( nextQ%isEmpty() ) exit
  !      
  !      call solve( room,nextQ%deQueue(),beforeQ%deQueue() )
  !    end do
      
      
      
      
      if( count(flag(2:n)==-1) >=1 )then
        print*,'No';stop
      end if
      
      print*,'Yes'
      do i = 2,n
        print*,flag(i)
      end do
      
      
      
      
      
      
   !   print*,n,m
   !   do i = 1,m
   !     print*,a(i),b(i)
   !   end do
      
      
   !   do i= 1,n
   !     print*,'room',i,room(i)%numNei
   !     print*,room(i)%nei
   !   end do
      
      END PROGRAM