Problem:
Score: 400 points

Problem Statement

There is a cave.

The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.

It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.

Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.

If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.

Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 2 \times 10^5

1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)

A_i \neq B_i\ (1 \leq i \leq M)

One can travel between any two rooms by traversing passages.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If there is no way to place signposts satisfying the objective, print No.

Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i.

Sample Input 1

4 4
1 2
2 3
3 4
4 2

Sample Output 1

Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:

Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.

Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \to 2 \to 1. This is the minimum number of passages possible.

Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \to 2 \to 1. This is the minimum number of passages possible.

Thus, the objective is satisfied.

Sample Input 2

6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6

Sample Output 2

Yes
6
5
5
1
1

If there are multiple solutions, any of them will be accepted.

Solution in Go (1.14.1) (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type loom struct {
	index int
	To []int
	count int
}
func main() {
	scan_init()
	n := scanInt()
	m := scanInt()
	a := make([]int, m)
	b := make([]int, m)
	sizes = make([]int, n)
	for i:= 0; i<n; i++ {
		sizes[i] = n+1
	}
	sizes[0] = 0
	looms = make([]loom, n)
	for i:= 0; i<n; i++ {
		looms[i].index = i
		looms[i].To = []int{}
	}
	for i:= 0 ; i<m; i++ {
		a[i] = scanInt()-1
		b[i] = scanInt()-1
		looms[a[i]].To = append(looms[a[i]].To, b[i])
		looms[b[i]].To = append(looms[b[i]].To, a[i])
	}
	// 幅優先探索
	output = make([]int, n) // n= 0 は飛ばす
	for i:= 0; i<n; i++ {
		output[i] = n+1
	}
	output[0] = 0
	BFS(0, 0, n)
	//que := looms[0].To
	//pre := 0
	//for len(que) > 0 {
	//	var value int
	//	value,que = shift(que)
	//	take := looms[pre].To
	//	fmt.Println(take, "take", output, pre)
	//	for i:= 0; i<len(take); i++ {
	//		if output[take[i]] == n+1{
	//			output[take[i]] = pre+1
	//			que = append(que, take[i])
	//		} else {
	//			continue
	//		}
	//	}
	//	pre = value
	//}
	// fmt.Println(looms, output)
	check := true
	for i:= 0; i<n; i++ {
		if output[i] == n+1 {
			check = false
		}
	}
	// fmt.Println(looms, output)
	if check {
		fmt.Println("Yes")
		for i:= 1; i<n; i++ {
			fmt.Println(output[i])
		}
	} else {
		fmt.Println("No", output)
	}
}
var output []int
var sizes []int
var looms []loom
func BFS (index int, size int, n int) {
	take := looms[index].To
	size++
	// fmt.Println("回数", size, index+1, take, output)
	for i:= 0; i<len(take); i++ {
		if sizes[take[i]] > size {
			output[take[i]] = index+1
			sizes[take[i]] = size
			BFS(take[i], size, n)
		} else {
			continue
		}
	}
}
var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}
func shift(slice []int) (int, []int){
	n := len(slice)
	value := slice[0]
	popSlice := slice[1:n]
	return value, popSlice
}