Takes a graph (as dict from el to list of elem) and returns a list of elements such that for each edge (a, b) in the graph, a comes before b in the list