Problem p02678 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())

nei_L = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    nei_L[a - 1].append(b - 1)
    nei_L[b - 1].append(a - 1)

ans = [-1] * N
queue = deque()


def bfs():
    queue.append(0)
    while queue:
        now = queue.popleft()

        for c in nei_L[now]:
            if ans[c] == -1:
                ans[c] = now
                queue.append(c)


bfs()

if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())

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

ans = [0] * N
queue = deque()


def bfs():
    queue.append(0)
    while queue:
        now = queue.popleft()

        for c in nei_L[now]:
            if ans[c] == -1:
                ans[c] = now
                queue.append(c)


bfs()
print("Yes")
for i in range(1, N):
    print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())

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

ans = [-1] * N
queue = deque()


def bfs():
    queue.append(0)
    while queue:
        now = queue.popleft()

        for c in nei_L[now]:
            if ans[c] == -1:
                ans[c] = now
                queue.append(c)


bfs()

if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())

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

ans = [-1] * N
queue = deque()


def bfs():
    queue.append(0)
    while len(queue) > 0:
        now = queue.popleft()

        for c in nei_L[now]:
            if ans[c] == -1:
                ans[c] = now
                queue.append(c)


bfs()

if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())

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

ans = [-1] * N
queue = deque()


def bfs():
    queue.append(0)
    while len(queue) > 0:
        now = queue.popleft()

        for c in nei_L[now]:
            if not ans[c] == -1:
                ans[c] = now
                queue.append(c)


bfs()

if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())

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

ans = [-1] * N
visited = [0] * N
queue = deque()

def bfs():
    queue.append(0)
    while len(queue) > 0:
        #if all(visited):
            #break
        now = queue.popleft()

        for c in nei_L[now]:

            if not visited[c]:
                ans[c] = now
                queue.append(c)
                visited[c] = 1


bfs()

if -1 in visited[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

# AB = [list(map(int, input().split)) for _ in range(M)]

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

ans = [-1] * N
visited = [0] * N

from collections import deque
queue = deque()

def bfs():
    queue.append(0)
    while len(queue) > 0:

        #if all(visited):
            #break
        now = queue.popleft()

        for c in nei_L[now]:

            if not visited[c]:
                ans[c] = now
                queue.append(c)
                visited[c] = 1

bfs()

#if -1 in visited[1:]:
#    print("No")
#else:
for i in range(N):
    if i == 0:
        print("Yes")
    else:
        print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

# AB = [list(map(int, input().split)) for _ in range(M)]

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

ans = [-1] * N
visited = [0] * N

from collections import deque
queue = deque()

def bfs():
    queue.append(0)
    while len(queue) > 0:

        #if all(visited):
            #break
        now = queue.popleft()

        for c in nei_L[now]:

            if not visited[c]:
                ans[c] = now
                queue.append(c)
                visited[c] = 1

bfs()

if -1 in visited[1:]:
    print("No")
else:
    for i in range(N):
        if i == 0:
            print("Yes")
        else:
            print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

# AB = [list(map(int, input().split)) for _ in range(M)]

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

ans = [-1] * N
visited = [0] * N

from collections import deque
queue = deque()

def bfs():
    queue.append(0)
    while len(queue) > 0:

        if all(visited):
            break
        now = queue.popleft()

        for c in nei_L[now]:
            if not visited[c]:
                ans[c] = now
                queue.append(c)
                visited[c] = 1

bfs()

if -1 in visited[1:]:
    print("No")
else:
    for i in range(N):
        if i == 0:
            print("Yes")
        else:
            print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

# AB = [list(map(int, input().split)) for _ in range(M)]

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

ans = [-1] * N
visited = [0] * N
cost = [0] * N

from collections import deque
queue = deque()

def bfs():
    queue.append(0)

    while len(queue) > 0:

        if all(visited):
            break
        now = queue.popleft()

        for c in nei_L[now]:
            if not visited[c]:
                ans[c] = now
                queue.append(c)
                cost[c] = cost[now] + 1
                visited[c] = 1

bfs()

if -1 in visited[1:]:
    print("No")
else:
    for i in range(N):
        if i == 0:
            print("Yes")
        else:
            print(ans[i] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

# AB = [list(map(int, input().split)) for _ in range(M)]

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

ans = [-1] * N
visited = [0] * N
cost = [0] * N

from collections import deque
queue = deque()

def bfs():
    queue.append(0)

    while len(queue) > 0:

        if all(visited):
            break
        now = queue.popleft()

        for c in nei_L[now]:
            if not visited[c]:
                ans[c] = now
                queue.append(c)
                cost[c] = cost[now] + 1
                visited[c] = 1

bfs()
print(ans)

if -1 in visited[1:]:
    print("No")
else:
    for i in range(N):
        if i == 0:
            print("Yes")
        else:
            print(ans[i] + 1)