Buggy python submission (verdict: Time Limit Exceeded):
import math
(r, p)=[int(n) for n in input().split()]
route_list=[[0 for j in range(r)] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x][y] = 1
  route_list[y][x] = 1 

node_num = len(route_list)

unsearched_nodes = list(range(node_num))
distance = [math.inf] * node_num
previous_nodes = [-1] * node_num
distance[0] = 0

def initial():
  unsearched_nodes = list(range(node_num))
  distance = [math.inf] * node_num
  previous_nodes = [-1] * node_num
  distance[0] = 0

def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0):
    posible_min_distance = math.inf
    for node_index in unsearched_nodes:
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index]
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes)
    unsearched_nodes.remove(target_min_index)

    target_edge = route_list[target_min_index]
    for index, route_dis in enumerate(target_edge):
        if route_dis != 0:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis
                previous_nodes[index] =  target_min_index

ans=[-1]*(r-1)
for i in range(1, r):
  if ans[i-1] != -1:
    continue
  previous_node = i
  string=""
  while previous_node != -1:
    if previous_node !=0:
        string += str(previous_node + 1) + " "
    else:
        string += str(previous_node + 1)
    previous_node = previous_nodes[previous_node]
  string = string.split()
  for i, v in enumerate(string[:-1]):
    ans[int(v)-2]=string[i+1]

if "No" in ans:
  print("No")
else:
  print("Yes")
  for i in ans:
    print(i)


Fixed submission:
(r, p)=[int(n) for n in input().split()]
route_list=[[] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x].append(y)
  route_list[y].append(x)

upstair=[0]
ans=[-1]*r
while upstair:
  tmp=[]
  for i in upstair:
    for j in route_list[i]:
      if ans[j] == -1:
        ans[j] = i + 1
        tmp.append(j)
  upstair=tmp

if -1 in ans:
  print("No")
else:
  print("Yes")
  for i in ans[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import math
(r, p)=[int(n) for n in input().split()]
route_list=[[0 for j in range(r)] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x][y] = 1
  route_list[y][x] = 1 

node_num = len(route_list)

unsearched_nodes = list(range(node_num))
distance = [math.inf] * node_num
previous_nodes = [-1] * node_num
distance[0] = 0

def initial():
  unsearched_nodes = list(range(node_num))
  distance = [math.inf] * node_num
  previous_nodes = [-1] * node_num
  distance[0] = 0

def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0):
    posible_min_distance = math.inf
    for node_index in unsearched_nodes:
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index]
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes)
    unsearched_nodes.remove(target_min_index)

    target_edge = route_list[target_min_index]
    for index, route_dis in enumerate(target_edge):
        if route_dis != 0:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis
                previous_nodes[index] =  target_min_index

ans=[-1]*(r-1)
for i in range(1, r):
  initial()
  if ans[i-1] != -1:
    continue
  previous_node = i
  string=""
  while previous_node != -1:
    if previous_node !=0:
        string += str(previous_node + 1) + " "
    else:
        string += str(previous_node + 1)
    previous_node = previous_nodes[previous_node]
  string = string.split()
  for i, v in enumerate(string[:-1]):
    ans[int(v)-2]=string[i+1]

if "No" in ans:
  print("No")
else:
  print("Yes")
  for i in ans:
    print(i)

Fixed submission:
(r, p)=[int(n) for n in input().split()]
route_list=[[] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x].append(y)
  route_list[y].append(x)

upstair=[0]
ans=[-1]*r
while upstair:
  tmp=[]
  for i in upstair:
    for j in route_list[i]:
      if ans[j] == -1:
        ans[j] = i + 1
        tmp.append(j)
  upstair=tmp

if -1 in ans:
  print("No")
else:
  print("Yes")
  for i in ans[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import math
(r, p)=[int(n) for n in input().split()]
route_list=[[0 for j in range(r)] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x][y] = 1
  route_list[y][x] = 1 

node_num = len(route_list)

unsearched_nodes = list(range(node_num))
distance = [math.inf] * node_num
previous_nodes = [-1] * node_num
distance[0] = 0

def initial():
  unsearched_nodes = list(range(node_num))
  distance = [math.inf] * node_num
  previous_nodes = [-1] * node_num
  distance[0] = 0

def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

while(len(unsearched_nodes) != 0):
    posible_min_distance = math.inf
    for node_index in unsearched_nodes:
        if posible_min_distance > distance[node_index]: 
            posible_min_distance = distance[node_index]
    target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes)
    unsearched_nodes.remove(target_min_index)

    target_edge = route_list[target_min_index]
    for index, route_dis in enumerate(target_edge):
        if route_dis != 0:
            if distance[index] > (distance[ target_min_index] + route_dis):
                distance[index] = distance[ target_min_index] + route_dis
                previous_nodes[index] =  target_min_index

ans=[]
for i in range(1, r):
  initial()
  previous_node = i
  string=""
  while previous_node != -1:
    if previous_node !=0:
        string += str(previous_node + 1) + " <- "
    else:
        string += str(previous_node + 1)
    previous_node = previous_nodes[previous_node]
  if len(string.split()) > 2:
    ans.append(string.split()[2])
  else:
    ans.append("No")

if "No" in ans:
  print("No")
else:
  print("Yes")
  for i in ans:
    print(i)

Fixed submission:
(r, p)=[int(n) for n in input().split()]
route_list=[[] for i in range(r)]
for i in range(p):
  (x, y)=[int(n)-1 for n in input().split()]
  route_list[x].append(y)
  route_list[y].append(x)

upstair=[0]
ans=[-1]*r
while upstair:
  tmp=[]
  for i in upstair:
    for j in route_list[i]:
      if ans[j] == -1:
        ans[j] = i + 1
        tmp.append(j)
  upstair=tmp

if -1 in ans:
  print("No")
else:
  print("Yes")
  for i in ans[1:]:
    print(i)