Street Directions |
According to the Automobile Collision Monitor (ACM), most fatal traffic accidents occur on two-way streets. In order to reduce the number of fatalities caused by traffic accidents, the mayor wants to convert as many streets as possible into one-way streets. You have been hired to perform this conversion, so that from each intersection, it is possible for a motorist to drive to all the other intersections following some route.
You will be given a list of streets (all two-way) of the city. Each street connects two intersections, and does not go through an intersection. At most four streets meet at each intersection, and there is at most one street connecting any pair of intersections. It is possible for an intersection to be the end point of only one street. You may assume that it is possible for a motorist to drive from each destination to any other destination when every street is a two-way street.
Input
The input consists of a number of cases. The first line of each case contains two integers n and m. The number of intersections is n ( ), and the number of streets is m. The next m lines contain the intersections incident to each of the m streets. The intersections are numbered from 1 to n, and each street is listed once. If the pair is present, will not be present. End of input is indicated by n = m = 0.
Output
For each case, print the case number (starting from 1) followed by a blank line. Next, print on separate lines each street as the pair to indicate that the street has been assigned the direction going from intersection i to intersection j. For a street that cannot be converted into a one-way street, print both and on two different lines. The list of streets can be printed in any order. Terminate each case with a line containing a single `#' character.
Note: There may be many possible direction assignments satisfying the requirements. Any such assignment is acceptable.
Sample Input
7 101 21 32 43 44 54 65 76 72 53 67 91 21 31 42 43 44 55 65 77 60 0
Sample Output
11 22 43 13 64 35 25 46 46 77 5#21 22 43 14 14 34 55 45 66 77 5#
Miguel A. Revilla 1999-03-24 tarjan遍历一遍,标记那些边是回边,需要走的非回边,桥,即可:
#include#include #include #include #include #include #include #include #include #include