Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = [[0 for i in range(N)]for j in range(N)]
    result = [0]*(N-1)
    record = [0]
    count = N-1
    in1 = 0
    in2 = 0

    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        if in1-1 < in2-1:
            aisle[in1-1][in2-1] = 1
        else:
            aisle[in2-1][in1-1] = 1

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        for i in range(N-1):
            if aisle[pop1][i+1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1
            if aisle[i+1][pop1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1

    if count == 0:
        print("Yes")
        for i in range(len(result)):
            print(result[i])
    else:
        print("No")


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = {}
    result = [0]*(N-1)
    record = [1]
    count = N-1
    in1 = 0
    in2 = 0

    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        aisle.setdefault(in1,[]).append(in2)
        aisle.setdefault(in2,[]).append(in1)

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        if pop1 in aisle:
            for i in aisle[pop1]:
                if result[i-2] == 0 and i >= 2:
                    result[i-2] = pop1
                    record.append(i)
                    count = count -1

    if count == 0:
        print("Yes")
        for i in range(len(result)):
            print(result[i])
    else:
        print("No")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = [[0 for i in range(N)]for j in range(N)]
    result = [0]*(N-1)
    record = [0]
    count = N-1
    in1 = 0
    in2 = 0
    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        if in1-1 < in2-1:
            aisle[in1-1][in2-1] = 1
        else:
            aisle[in2-1][in1-1] = 1

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        for i in range(N-1):
            if aisle[pop1][i+1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1
            if aisle[i+1][pop1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1

    if count == 0:
        print("Yes")
    else:
        print("No")
    for i in range(len(result)):
        print(result[i])


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = {}
    result = [0]*(N-1)
    record = [1]
    count = N-1
    in1 = 0
    in2 = 0

    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        aisle.setdefault(in1,[]).append(in2)
        aisle.setdefault(in2,[]).append(in1)

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        if pop1 in aisle:
            for i in aisle[pop1]:
                if result[i-2] == 0 and i >= 2:
                    result[i-2] = pop1
                    record.append(i)
                    count = count -1

    if count == 0:
        print("Yes")
        for i in range(len(result)):
            print(result[i])
    else:
        print("No")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = [[0 for i in range(N)]for j in range(N)]
    result = [0]*(N-1)
    record = [0]
    count = N-1
    in1 = 0
    in2 = 0
    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        if in1-1 < in2-1:
            aisle[in1-1][in2-1] = 1
        else:
            aisle[in2-1][in1-1] = 1

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        for i in range(N-1):
            if aisle[pop1][i+1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1
            if aisle[i+1][pop1] == 1 and result[i] == 0:
                result[i] = pop1+1
                record.append(i+1)
                count = count - 1

    if count == 0:
        print("Yes")
    else:
        print("No")
    for i in range(len(result)):
        print(result[i])


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    input1 = input()
    input1 = input1.split()
    N = int(input1[0])
    M = int(input1[1])

    aisle = {}
    result = [0]*(N-1)
    record = [1]
    count = N-1
    in1 = 0
    in2 = 0

    for i in range(M):
        input2 = input()
        input2 = input2.split()
        in1 = int(input2[0])
        in2 = int(input2[1])
        aisle.setdefault(in1,[]).append(in2)
        aisle.setdefault(in2,[]).append(in1)

    while count != 0 and len(record) != 0:
        pop1 = record.pop(0)
        if pop1 in aisle:
            for i in aisle[pop1]:
                if result[i-2] == 0 and i >= 2:
                    result[i-2] = pop1
                    record.append(i)
                    count = count -1

    if count == 0:
        print("Yes")
        for i in range(len(result)):
            print(result[i])
    else:
        print("No")


if __name__ == "__main__":
    main()