Given a directed graph with vertices and arcs, can you keep exactly arcs (and remove the rest) in such a way that every vertex belongs to one cycle of the resulting graph?
Input consists of several cases, each one with and , followed by pairs to indicate an arc from to , with . Assume , , that vertices are numbered from 0 to , and that there are no repeated arcs.
Print one line for every given graph. If there is no solution, print
“no”. Otherwise, print “yes” followed by the
chosen arcs in any order. If there is more than one solution, you can
print any one. Follow strictly the format of the sample output.
Consider the max-flow problem.
Input
3 3 0 1 1 2 2 0 3 4 0 1 1 2 2 1 1 0 4 6 0 2 2 1 1 3 3 0 2 0 3 1 4 6 0 2 2 1 1 3 3 0 2 0 3 1
Output
yes 0 1 1 2 2 0 no yes 0 2 1 3 2 1 3 0 yes 2 0 3 1 1 3 0 2