A algorithm:
Looking into 0 degree (no nodes pointing to it) node Q, Q and delete Q connected sides.
Repeating the above operation is deleted until all nodes, can not be found, or the degree of node 0 (the presence of the ring, non-DAG).
Algorithms II:
Traversing each node, access to all descendant nodes via DFS. No descendant of the current node when a boundary recursion, the node is added to the current topology sequence header .
Note that, to judge whether a recursive way there is encountered the ring node, so use \ (vis [u] \) storage node state:
\ (vis [u] = 0 \) , the junction point \ (U \) never visited;
\ (vis [u] = - 1 \) , the junction point \ (U \) is available;
\ (vis [u] = 1 \) , the junction point \ (U \) has finished accessing.