Buggy python submission (verdict: Time Limit Exceeded):
## ---- DFS
class Node(object):
    def __init__(self, name):
        self.name = name
    def getName(self):
        return self.name
    def __str__(self):
        return self.name
    
class Edge(object):
    def __init__(self, src, dest):
        self.src = src
        self.dest = dest
    def getSource(self):
        return self.src
    def getDestination(self):
        return self.dest
    def __str__(self):
        return self.src.getName() + '->' + self.dest.getName()
    
class WeightedEdje(Edge):
    def __init__(sekf, src, dest, weight=1.0):
        self.src = scr
        self.dest = dest
        self.weight = weight
    def getWeight(self):
        return self.weight
    def __str__(self):
        return self.src.getName() + '->(' + str(self.weight) + ')' + self.dest.getName()

class Digraph(object):
    def __init__(self):
        self.nodes = []
        self.edges = {}
    def addNode(self, node):
        if node in self.nodes:
            raise ValueError('Duplicate node')
        else:
            self.nodes.append(node)
            self.edges[node] = []
    def addEdge(self, edge):
        src = edge.getSource()
        dest = edge.getDestination()
        if not (src in self.nodes and dest in self.nodes):
            raise ValueError('node not in graph')
        self.edges[src].append(dest)
    def childrenOf(self, node):
        return self.edges[node]
    def hasNode(self, node):
        return node in self.nodes
    def __str__(self):
        result=''
        for src in self.nodes:
            for dest in self.nodes:
                result = result + src.getName() + '->' + dest.getName() + '\n'
        return result[:-1]
            
class Graph(Digraph):
    def addEdge(self, edge):
        addEdge(self, edge)
        Digraph.addEdge(self, edge)
        rev  = Edge(edge.getDestination(), edge.getSorce())
        Digraph.addEdge(self, rev)

def DFS(graph,start,end,path,shortest):
    path = path + [start]
    if start == end:
        return path
    for node in graph.childrenOf(start):
        if node not in path:
            if shortest == None or len(path) < len(shortest):
                newPath = DFS(graph, node, end, path, shortest)
                if newPath != None:
                    shortest = newPath
    return shortest

def shortestPath(graph, start, end):
    return DFS(graph, start, end, [], None)

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

g = Digraph()
for n in range(1,N+1):
    g.addNode(n)

for _ in range(M):
    a,b = list(map(int,input().split()))
    g.addEdge(Edge(a,b))
    g.addEdge(Edge(b,a))


err = False
rets = [0] * (N+1)
for i in range(2,N+1):
    if i not in rets:
        sp = shortestPath(g,i,1)
        if len(sp) == 0:
            err = True
            break
        for i in range(len(sp)-1):
            rets[sp[i]] = sp[i+1]

if err == False:
    print("Yes")
    for i in range(2,N+1):
        print(rets[i])
else:
    print("No")


Fixed submission:
from collections import deque

def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited


## ----main
N, M = list(map(int,input().split()))
graph = [[] for _ in range(N)]

for _ in range(M):
    a,b = list(map(int,input().split()))
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

visited = bfs(graph,N,0)

if all(visited[1:]):
    print("Yes")
    print(*visited[1:], sep="\n")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
## ---- DFS
class Node(object):
    def __init__(self, name):
        self.name = name
    def getName(self):
        return self.name
    def __str__(self):
        return self.name
    
class Edge(object):
    def __init__(self, src, dest):
        self.src = src
        self.dest = dest
    def getSource(self):
        return self.src
    def getDestination(self):
        return self.dest
    def __str__(self):
        return self.src.getName() + '->' + self.dest.getName()
    
class WeightedEdje(Edge):
    def __init__(sekf, src, dest, weight=1.0):
        self.src = scr
        self.dest = dest
        self.weight = weight
    def getWeight(self):
        return self.weight
    def __str__(self):
        return self.src.getName() + '->(' + str(self.weight) + ')' + self.dest.getName()

class Digraph(object):
    def __init__(self):
        self.nodes = []
        self.edges = {}
    def addNode(self, node):
        if node in self.nodes:
            raise ValueError('Duplicate node')
        else:
            self.nodes.append(node)
            self.edges[node] = []
    def addEdge(self, edge):
        src = edge.getSource()
        dest = edge.getDestination()
        if not (src in self.nodes and dest in self.nodes):
            raise ValueError('node not in graph')
        self.edges[src].append(dest)
    def childrenOf(self, node):
        return self.edges[node]
    def hasNode(self, node):
        return node in self.nodes
    def __str__(self):
        result=''
        for src in self.nodes:
            for dest in self.nodes:
                result = result + src.getName() + '->' + dest.getName() + '\n'
        return result[:-1]
            
class Graph(Digraph):
    def addEdge(self, edge):
        addEdge(self, edge)
        Digraph.addEdge(self, edge)
        rev  = Edge(edge.getDestination(), edge.getSorce())
        Digraph.addEdge(self, rev)

def DFS(graph,start,end,path,shortest):
    path = path + [start]
    if start == end:
        return path
    for node in graph.childrenOf(start):
        if node not in path:
            if shortest == None or len(path) < len(shortest):
                newPath = DFS(graph, node, end, path, shortest)
                if newPath != None:
                    shortest = newPath
    return shortest

def shortestPath(graph, start, end):
    return DFS(graph, start, end, [], None)

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

g = Digraph()
for n in range(1,N+1):
    g.addNode(n)

for _ in range(M):
    a,b = list(map(int,input().split()))
    g.addEdge(Edge(a,b))
    g.addEdge(Edge(b,a))


err = False
paths = []
for i in range(2,N+1):
    ret = shortestPath(g,i,1)
    if len(ret) == 0:
        break
    paths.append(ret)

if err == False:
    print("Yes")
    for p in paths:
        print(p[1])
else:
    print("No")


Fixed submission:
from collections import deque

def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited


## ----main
N, M = list(map(int,input().split()))
graph = [[] for _ in range(N)]

for _ in range(M):
    a,b = list(map(int,input().split()))
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

visited = bfs(graph,N,0)

if all(visited[1:]):
    print("Yes")
    print(*visited[1:], sep="\n")
else:
    print("No")