Move function level import to module level.
Use set literal instead of set().
PEP 8.
Raise NetworkXNoCycle when no cycles are found.