Language: C++

import heapq

# def heapify(x):
#     for i in range((x)):
#         x[i] = -x[i]
#     heapq.heapify(x)

# def heappush(heap, item):
#     heapq.heappush(heap, -item)

# def heappop(heap):
#     return -heapq.heappop(heap)

# from heapq import heappop, heappush
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None


rooms_count, passages_count = map(int, raw_input().split())
matrix = []
for i in range(0, rooms_count):
    matrix.append([])
    for j in range(0, rooms_count):
        matrix[i].append(False)

for j in range(0, passages_count):
    a, b = map(int, raw_input().split())
    matrix[a - 1][b - 1] = True
    matrix[b - 1][a - 1] = True

seen = set()
distance = [10000] * rooms_count
next = [10000] * rooms_count
h = []
heapq.heappush(h, (0, 0, -1))
while len(h):
    (d, room, parent) = heapq.heappop(h)
    if (distance[room] <= d):
        continue
    distance[room] = d
    next[room] = parent
    seen.add(room)

    for neighbor in range(0, rooms_count):
        if neighbor != room and matrix[room][neighbor]:
            heapq.heappush(h, (d + 1, neighbor, room))

if len(seen) == rooms_count:
    print('Yes')
    for room in range(1, rooms_count):
        print(next[room] + 1)
else:
    print('No')


Compiler output:
a.cc:3:3: error: invalid preprocessing directive #def; did you mean #ifdef?
    3 | # def heapify(x):
      |   ^~~
      |   ifdef
a.cc:4:7: error: invalid preprocessing directive #for
    4 | #     for i in range((x)):
      |       ^~~
a.cc:5:11: error: invalid preprocessing directive #x
    5 | #         x[i] = -x[i]
      |           ^
a.cc:6:7: error: invalid preprocessing directive #heapq
    6 | #     heapq.heapify(x)
      |       ^~~~~
a.cc:8:3: error: invalid preprocessing directive #def; did you mean #ifdef?
    8 | # def heappush(heap, item):
      |   ^~~
      |   ifdef
a.cc:9:7: error: invalid preprocessing directive #heapq
    9 | #     heapq.heappush(heap, -item)
      |       ^~~~~
a.cc:11:3: error: invalid preprocessing directive #def; did you mean #ifdef?
   11 | # def heappop(heap):
      |   ^~~
      |   ifdef
a.cc:12:7: error: invalid preprocessing directive #return
   12 | #     return -heapq.heappop(heap)
      |       ^~~~~~
a.cc:14:3: error: invalid preprocessing directive #from
   14 | # from heapq import heappop, heappush
      |   ^~~~
a.cc:15:3: error: invalid preprocessing directive #Definition
   15 | # Definition for a binary tree node.
      |   ^~~~~~~~~~
a.cc:16:3: error: invalid preprocessing directive #class
   16 | # class TreeNode:
      |   ^~~~~
a.cc:17:7: error: invalid preprocessing directive #def; did you mean #ifdef?
   17 | #     def __init__(self, x):
      |       ^~~
      |       ifdef
a.cc:18:11: error: invalid preprocessing directive #self
   18 | #         self.val = x
      |           ^~~~
a.cc:19:11: error: invalid preprocessing directive #self
   19 | #         self.left = None
      |           ^~~~
a.cc:20:11: error: invalid preprocessing directive #self
   20 | #         self.right = None
      |           ^~~~
a.cc:53:11: warning: multi-character character constant [-Wmultichar]
   53 |     print('Yes')
      |           ^~~~~
a.cc:57:11: warning: multi-character character constant [-Wmultichar]
   57 |     print('No')
      |           ^~~~
a.cc:1:1: error: 'import' does not name a type
    1 | import heapq
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'