def topoSort(graph):
    in_degrees = dict(((u, 0) for u in graph))
    num = len(in_degrees)
    for u in graph:
        for v in graph[u]:
            in_degrees[v] += 1
    Q = [u for u in in_degrees if (in_degrees[u] == 0)]
    Seq = []
    while Q:
        u = Q.pop()
        Seq.append(u)
        for v in graph[u]:
            in_degrees[v] -= 1
            if (in_degrees[v] == 0):
                Q.append(v)
    if (len(Seq) == num):
        return Seq
    else:
        return None
def topoSort(graph):
    in_degrees = dict(((u, 0) for u in graph))
    num = len(in_degrees)
    for u in graph:
        for v in graph[u]:
            in_degrees[v] += 1
    Q = [u for u in in_degrees if (in_degrees[u] == 0)]
    Seq = []
    while Q:
        u = Q.pop()
        Seq.append(u)
        for v in graph[u]:
            in_degrees[v] -= 1
            if (in_degrees[v] == 0):
                Q.append(v)
    if (len(Seq) == num):
        return Seq
    else:
        return None