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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] == 0:
                ans[next] = t + 1
            if L[next][0] == 0:
                dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] == 0:
                ans[next] = t + 1
            if L[next][0] == 0:
                dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            if ans[L[t][i]] == 0:
                ans[L[t][i]] = t + 1
            if L[L[t][i]][0] == 0:
                dq.append(L[t][i])
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    d = [0] * n
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            dti = d[L[t][i]]
            if dti == 0 or dti > d[t] + 1:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
            if L[L[t][i]][0] == 0:
                dq.append(L[t][i])
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    d = [0] * n
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            dti = d[L[t][i]]
            if dti == 0 or dti > d[t] + 1:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
            if L[L[t][i]][0] == 0:
                dq.append(L[t][i])
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    d = [0] * n
    ans = [0] * n
    dq = deque([0])
    while len(dq) > 0:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            if d[L[t][i]] == 0:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
            else:
                if d[L[t][i]] > d[t] + 1:
                    d[L[t][i]] = d[t] + 1
                    ans[L[t][i]] = t + 1
            if L[L[t][i]][0] == 0:
                dq.append(L[t][i])
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

n, m = map(int, input().split())
L = [[0] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
L[0][0] = 1
d = [0] * n
ans = [0] * n
dq = deque([0])
while len(dq) > 0:
    t = dq.popleft()
    for i in range(1, len(L[t])):
        if d[L[t][i]] == 0:
            d[L[t][i]] = d[t] + 1
            ans[L[t][i]] = t + 1
        else:
            if d[L[t][i]] > d[t] + 1:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
        if L[L[t][i]][0] == 0:
            dq.append(L[t][i])
    else:
        L[t][0] = 1
print('Yes')
print(*ans[1:], sep='\n')

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()

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

n, m = map(int, input().split())
L = [[0] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
L[0][0] = 1
d = [0] * n
ans = [0] * n
dq = deque([0])
while len(dq) > 0:
    t = dq.popleft()
    for i in range(1, len(L[t])):
        if d[L[t][i]] == 0:
            d[L[t][i]] = d[t] + 1
            ans[L[t][i]] = t + 1
        else:
            if d[L[t][i]] > d[t] + 1:
                d[L[t][i]] = d[t] + 1
                ans[L[t][i]] = t + 1
        if L[L[t][i]][0] == 0:
            dq.append(L[t][i])
    else:
        L[t][0] = 1
print('Yes')
print(*ans[1:], sep='\n')


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    L = [[0] for _ in range(n)]
    for _ in [0] * m:
        a, b = map(int, input().split())
        L[a-1].append(b-1)
        L[b-1].append(a-1)
    L[0][0] = 1
    ans = [0] * n
    dq = deque([0])
    while dq:
        t = dq.popleft()
        for i in range(1, len(L[t])):
            next = L[t][i]
            if ans[next] != 0:
                continue
            ans[next] = t + 1
            dq.append(next)
        else:
            L[t][0] = 1
    print('Yes')
    print(*ans[1:], sep='\n')

main()