John's trip
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8960 Accepted: 3002 Special Judge
Description
Little Johnny has got a new car. He decided to drive aroundthe town to visit his friends. Johnny wanted to visit all his friends, but there was many of them. In each street he had one friend. He started thinking how to make his trip as short as possible. Very soon he realized thatthe best way to do it was to travel through each street of town only once. Naturally, he wanted to finish his trip atthe same place he started, at his parents' house.
The streets in Johnny's town were named byinteger numbers from1to n, n < 1995. The junctions were independently named byinteger numbers from1to m, m <= 44. No junction connects more than 44 streets. All junctions inthe town had different numbers. Each street was connecting exactly two junctions. No two streets inthe town had the same number. He immediately started to plan his round trip. If there was more than one such round trip, he would have chosen the one which, when written down as a sequence of street numbers is lexicographically the smallest. But Johnny was not able to find even one such round trip.
Help Johnny andwrite a program which finds the desired shortest round trip. If theround trip doesnot exist the program should write a message. Assume that Johnny lives atthe junction ending the street appears firstinthe input with smaller number. All streets inthe town are two way. There exists a way from each street to another street inthe town. The streets inthe town are very narrow and there is no possibility to turn backthe car once he isinthe street
Input
Input file consists of several blocks. Each block describes one town. Each line inthe block contains three integers x; y; z, where x > 0and y > 0 are the numbers of junctions which are connected bythe street number z. The endofthe block is marked bythe line containing x = y = 0. At theendofthe input file there is an empty block, x = y = 0.
Output
Output one line of each block containsthe sequence of street numbers (single members ofthe sequence are separated byspace) describing Johnny's round trip. If theround trip cannot be found the corresponding output block containsthe message "Round trip does not exist."
Sample Input
121232316125233314001212321332440000
Sample Output
123546
Round trip doesnot exist.