func readIntTuple() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

let (N, M) = readIntTuple()
var adjacent: [[Int]] = Array(repeating: [], count: N + 1)
(1...M).forEach({ _ in
    let (A, B) = readIntTuple()
    adjacent[A].append(B)
    adjacent[B].append(A)
})

var parent = Array(repeating: -1, count: N + 1)
var queue = [1]
while !queue.isEmpty {
    var nextQueue: [Int] = []
    queue.forEach({ room in
        adjacent[room].forEach({
            if parent[$0] < 0 {
                parent[$0] = room
                nextQueue.append($0)
            }
        })
    })
    queue = nextQueue
}

print("Yes")
(2...N).forEach({print(parent[$0])})
