keep nodes in the visited list
put external nodes in a subgraph