Problem:
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.

Incorrect submission (verdict: Wrong Answer):
import glob
import math



REL_PATH = 'ABC\\168\\D'


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, max, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, 0, N)
            return

        for i in range(0, max+2):
            if i == N:
                return
            result[now] = i
            if i > max:
                self.rec(result, now+1, i, N)
            else:
                self.rec(result, now+1, max, N)

    def resolve(self):

        count = 0

        N, M = map(int, self.input_data().split())
        node = [list(map(int, self.input_data().split())) for i in range(M)]
        sp = [[0, 200000] for i in range(N+1)]   # signpost
        path = [[] for i in range(N+1)]
        for n in node:
            path[n[0]].append(n[1])
            path[n[1]].append(n[0])

        next = [1]
        sp[1][1] = 0
        while len(next) != 0:
            now = next.pop(0)
            for n in path[now]:
                if sp[n][1] > sp[now][1]+1:
                    sp[n][0] = now
                    sp[n][1] = sp[now][1]+1
                    next.append(n)


        print('yes')
        for i in range(2,N+1):
            print(str(sp[i][0]))

solver = Solver(REL_PATH)
solver.exec_resolve()


Fixed, accepted submission:
import glob
import math



REL_PATH = 'ABC\\168\\D'


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    alph = []

    def rec(self, result, now, max, N):

        if now == N:
            res = ""
            for i in result:
                res += self.alph[i]
            print(res)
            return

        if now == 0:
            result[0] = 0
            self.rec(result, now+1, 0, N)
            return

        for i in range(0, max+2):
            if i == N:
                return
            result[now] = i
            if i > max:
                self.rec(result, now+1, i, N)
            else:
                self.rec(result, now+1, max, N)

    def resolve(self):

        count = 0

        N, M = map(int, self.input_data().split())
        node = [list(map(int, self.input_data().split())) for i in range(M)]
        sp = [[0, 200000] for i in range(N+1)]   # signpost
        path = [[] for i in range(N+1)]
        for n in node:
            path[n[0]].append(n[1])
            path[n[1]].append(n[0])

        next = [1]
        sp[1][1] = 0
        while len(next) != 0:
            now = next.pop(0)
            for n in path[now]:
                if sp[n][1] > sp[now][1]+1:
                    sp[n][0] = now
                    sp[n][1] = sp[now][1]+1
                    next.append(n)


        print('Yes')
        for i in range(2,N+1):
            print(str(sp[i][0]))

solver = Solver(REL_PATH)
solver.exec_resolve()