Time Needed to Inform All Employees

from collections import deque

class Solution:
    def numOfMinutes(self, n, headID, manager, informTime):
        G = {}
        for u, v in enumerate(manager):
            if v not in G:
                G[v] = []
            G[v].append(u)

        dq = deque([])
        vset = set([])

        cmax = 0
        dq.append((0, -1))
        while dq:
            N = len(dq)
            for _ in range(N):
                ctime, idx = dq.popleft()
                cmax = max(cmax, ctime)
                for adj in G.get(idx, []):
                    if adj not in vset:
                        vset.add(adj)
                        dq.append((ctime + informTime[adj], adj))
        return cmax