Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)


Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)


Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n , m = map(int, input().split())

root = [0]*n
for i in range(m):
    r = list(map(int, input().split()))
    if root[r[0]-1] == 0:
        root[r[0]-1] = [r]
    else:
        root[r[0]-1] = root[r[0]-1]+[r]
    if root[r[1]-1] == 0:
        root[r[1]-1] = [r]
    else:
        root[r[1]-1] = root[r[1]-1]+[r]

kakutei = [1]

answer_li = [0]*n

def dest(r,k):
    if r[0] == k:
        return r[1]
    else:
        return r[0] 

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        d = dest(r,k)
        if answer_li[d-1] == 0:
            kakutei.append(d)
            answer_li[d-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)


Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n , m = map(int, input().split())

root = [0]*n
for i in range(m):
    r = list(map(int, input().split()))
    if root[r[0]-1] == 0:
        root[r[0]-1] = [r]
    else:
        root[r[0]-1] = root[r[0]-1]+[r]
    if root[r[1]-1] == 0:
        root[r[1]-1] = [r]
    else:
        root[r[1]-1] = root[r[1]-1]+[r]

kakutei = [1]

answer_li = [0]*n

mitou = [-1]*n

def dest(r,k):
    if r[0] == k:
        return r[1]
    else:
        return r[0] 

while len(kakutei)>=1:
    k = kakutei[0]
    for r in root[k-1]:
        d = dest(r,k)
        if mitou[d-1] == -1:
            mitou[d-1] = 0
            root[d-1].remove(r)
            kakutei.append(d)
            answer_li[d-1] = k

    kakutei = kakutei[1:]

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)


Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n , m = map(int, input().split())

root = []
for i in range(m):
    root.append(list(map(int, input().split())))

#room_li = list(range(1,n+1))

answer_li  = [0]*n

now_li  = [1]

next_now = []

delete_li = []

while True:
    for n in now_li:
        for i, r in enumerate(root):
            if n in r:
                #root.pop(i)
                delete_li.append(i)
                r.remove(n)
                dest = r[0]
                if answer_li[dest-1] == 0:
                    answer_li[dest-1] = n
                next_now.append(dest)
        cnt = 0
        for d in delete_li:
            root.pop(d-cnt)
            cnt += 1
        delete_li = []
    now_li = next_now
    next_now = []

    if len(root) <=1:
        break
answer_li = answer_li[1:]
if 0 not in answer_li:
    print('Yes')
    for i in answer_li:
        print(i)
else:
    print('No')



Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n , m = map(int, input().split())

root = []
for i in range(m):
    root.append(list(map(int, input().split())))

#room_li = list(range(1,n+1))

answer_li  = [0]*n

now_li  = [1]

next_now = []

delete_li = []

while True:
    for n in now_li:
        for i, r in enumerate(root):
            if n in r:
                #root.pop(i)
                delete_li.append(i)
                r.remove(n)
                dest = r[0]
                if answer_li[dest-1] == 0:
                    answer_li[dest-1] = n
                next_now.append(dest)
        cnt = 0
        for d in delete_li:
            root.pop(d-cnt)
            cnt += 1
        delete_li = []
    now_li = next_now
    next_now = []

    if len(root) <=1:
        break
answer_li = answer_li[1:]
if 0 not in answer_li:
    print('Yes')
    for i in answer_li:
        print(i)
else:
    print('No')



Fixed submission:
n , m = map(int, input().split())

root = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    root[a-1].append(b)
    root[b-1].append(a)

kakutei = [1]

answer_li = [0]*n

while kakutei:
    k = kakutei.pop(0)
    for r in root[k-1]:
        if answer_li[r-1] == 0:
            kakutei.append(r)
            answer_li[r-1] = k

answer_li = answer_li[1:]
if 0 in answer_li:
    print('No')
else:
    print('Yes')
    for i in answer_li:
        print(i)