class Solution:
def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
N = len(rooms)
graph = [[] for _ in range(N)]
for i, v in enumerate(rooms):
for j in v:
graph[i].append(j)
visited = [False]
visited[0] = True
q = collections.deque([0])
while q:
curr = q.popleft()
for i in graph[curr]:
if not visited[i]:
visited[i] = True
q.append(i)
return all(visited)