
@ExperimentalStdlibApi
fun main() {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val guide = IntArray(n){-1}
    val nodes = Array(n){mutableListOf<Int>()}
    repeat(m) {
        val (a, b) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
        nodes[a].add(b)
        nodes[b].add(a)
    }
    val queue = ArrayDeque<Int>().also{it.add(0)}
    while (queue.isNotEmpty()) {
        val top = queue.removeFirst()
        for (next in nodes[top]) if (guide[next] < 0) {
            guide[next] = top
            queue.addLast(next)
        }
    }
    println("Yes")
    println(guide.drop(1).joinToString("\n"){"${it + 1}"})
}