from collections import deque

def bfs(graph, start):
    visited = [False] * len(graph)
    q = deque()

    visited[start] = True
    q.append(start)

    while q:
        node = q.popleft()
        print(node, end=" ")

        for i in range(len(graph)):
            if graph[node][i] == 1 and not visited[i]:
                visited[i] = True
                q.append(i)

# Adjacency Matrix
graph = [
    [0, 1, 1, 0],
    [1, 0, 1, 1],
    [1, 1, 0, 0],
    [0, 1, 0, 0]
]

bfs(graph, 0)