q = deque()
q.append(start)
visited = set()
visited.add(start)
while q:
    u = q.popleft()

    for v in adj[u]:
        if v not in visited:
            visited.add(v)
            q.append(v)

Problems

2092. Find All People With Secret

 1q = deque()
 2q.append([0, 0])
 3q.append([0, firstPerson])
 4earliest = [inf] *  n
 5earliest[0] = 0
 6earliest[firstPerson] = 0
 7while q:
 8    time, u = q.popleft()
 9    for t, v in adj[u]:
10        if t >= time and t < earliest[v]:
11            earliest[v] = t
12            q.append([t, v])