Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)] #各node(index)から繋がるnode(value)
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [0 for i in range(N+1)]
    q = deque([1])
    visited = []
    while q:
        node = q.popleft()
        visited.append(node)
        for e in edge[node]:
            if e in visited:
                continue
            if signpost[e] == 0:
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print('{:.1g}'.format(i))        

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [None] * (N+1)
    signpost[0] = signpost[1] = 0
    q = deque([1])
    dist = [0 for i in range(N+1)]
    while q:
        node = q.popleft()
        for e in edge[node]:
            if signpost[e] is None:
                dist[e] = dist[node] + 1
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import time
import queue
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    root = [list(map(int, input().split(' '))) for i in range(M)]
    signpost = [0 for i in range(N+1)]

    q = deque([1])
    visited = []
    while len(q)!=0:
        #print(q)
        node = q.popleft()
        visited.append(node)
        #探索
        for nodes in root:
            if nodes[0] == node:
                if not (nodes[1] in visited or nodes[1] in q):
                    signpost[nodes[1]] = node
                    q.append(nodes[1])
            elif nodes[1] == node:
                if not (nodes[0] in visited or nodes[0] in q):
                    signpost[nodes[0]] = node
                    q.append(nodes[0])
    #print(visited)
    print('Yes')
    for i in signpost[2:]:
        print('{:.1g}'.format(i))        

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [None] * (N+1)
    signpost[0] = signpost[1] = 0
    q = deque([1])
    dist = [0 for i in range(N+1)]
    while q:
        node = q.popleft()
        for e in edge[node]:
            if signpost[e] is None:
                dist[e] = dist[node] + 1
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import numpy as np
def main():
    line = input().split(' ')
    N, M = int(line[0]), int(line[1])
    root = np.asarray([list(map(int, input().split(' '))) for i in range(M)])
    #signpost = [0 for i in range(N+1)]
    signpost = np.zeros(N+1)

    mem1 = [1]
    for i in range(M):
        mem2 = []
        for node in root:
            if node[0] in mem1:
                if signpost[node[1]] == 0 and node[1] != 1:
                    signpost[node[1]] = node[0]
                    mem2.append(node[1])
            elif node[1] in mem1:
                if signpost[node[0]] == 0 and node[0] != 1:
                    signpost[node[0]] = node[1]
                    mem2.append(node[0])
        if len(mem2) == 0:
            break
        mem1.clear()
        #list(set(mem2))
        mem1 = copy.copy(mem2)

    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print('{:.1g}'.format(i))        

if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [None] * (N+1)
    signpost[0] = signpost[1] = 0
    q = deque([1])
    dist = [0 for i in range(N+1)]
    while q:
        node = q.popleft()
        for e in edge[node]:
            if signpost[e] is None:
                dist[e] = dist[node] + 1
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
def main():
    line = input().split(' ')
    N, M = int(line[0]), int(line[1])
    root = [list(map(int, input().split(' '))) for i in range(M)]
    signpost = [0 for i in range(N+1)]

    mem1 = [1]
    while True:
        mem2 = []
        for node in root:
            if node[0] in mem1:
                if signpost[node[1]] == 0 and node[1] != 1:
                    signpost[node[1]] = node[0]
                    mem2.append(node[1])
            elif node[1] in mem1:
                if signpost[node[0]] == 0 and node[0] != 1:
                    signpost[node[0]] = node[1]
                    mem2.append(node[0])
        if len(mem2) == 0:
            break
        mem1.clear()
        #list(set(mem2))
        mem1 = copy.copy(mem2)

    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [None] * (N+1)
    signpost[0] = signpost[1] = 0
    q = deque([1])
    dist = [0 for i in range(N+1)]
    while q:
        node = q.popleft()
        for e in edge[node]:
            if signpost[e] is None:
                dist[e] = dist[node] + 1
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
def main():
    line = input().split(' ')
    N, M = int(line[0]), int(line[1])
    root = [list(map(int, input().split(' '))) for i in range(M)]
    signpost = [0 for i in range(N+1)]

    mem1 = [1]
    while True:
        mem2 = []
        for node1, node2 in root:
            if node1 in mem1:
                if signpost[node2] == 0 and node2 != 1:
                    signpost[node2] = node1
                    mem2.append(node2)
            if node2 in mem1:
                if signpost[node1] == 0 and node1 != 1:
                    signpost[node1] = node2 
                    mem2.append(node1)
        if len(mem2) == 0:
            break
        mem1.clear()
        list(set(mem2))
        mem1 = copy.copy(mem2)

    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    edge = [[] for i in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split(' '))
        edge[a].append(b)
        edge[b].append(a)
    signpost = [None] * (N+1)
    signpost[0] = signpost[1] = 0
    q = deque([1])
    dist = [0 for i in range(N+1)]
    while q:
        node = q.popleft()
        for e in edge[node]:
            if signpost[e] is None:
                dist[e] = dist[node] + 1
                signpost[e] = node
                q.append(e)
    if 0 in signpost[2:]:
        print('No')
    else:
        print('Yes')
        for i in signpost[2:]:
            print(i)        

if __name__ == "__main__":
    main()