for s in roots:
    print(s)
spacer = {s: 0}
for prereq, target in nx.dfs_edges(G, s):
    spacer[target] = spacer[prereq] + 2
print('{spacer}+-{t}'.format(spacer=' ' * spacer[prereq], t=target))
print('')
Построить граф зависимостей в python