网址链接
Description
Little Johnny has got a new car. He decided to drive around the 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 that the best way to do it was to travel through each street of town only once. Naturally, he wanted to finish his trip at the same place he started, at his parents’ house.
The streets in Johnny’s town were named by integer numbers from 1 to n, . The junctions were independently named by integer numbers from 1 to m, . No junction connects more than 44 streets. All junctions in the town had different numbers. Each street was connecting exactly two junctions. No two streets in the 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 and write a program which finds the desired shortest round trip. If the round trip does not exist the program should write a message. Assume that Johnny lives at the junction ending the street appears first in the input with smaller number. All streets in the town are two way. There exists a way from each street to another street in the town. The streets in the town are very narrow and there is no possibility to turn back the car once he is in the street
Input
Input file consists of several blocks. Each block describes one town. Each line in the block contains three integers x; y; z, where x > 0 and y > 0 are the numbers of junctions which are connected by the street number z. The end of the block is marked by the line containing x = y = 0. At the end of the input file there is an empty block, x = y = 0.
Output
Output one line of each block contains the sequence of street numbers (single members of the sequence are separated by space) describing Johnny’s round trip. If the round trip cannot be found the corresponding output block contains the message “Round trip does not exist.”
Sample Input
Sample Output
题意:
给出m个点m<=44,n条边,n<1995的图,问是否有欧拉回路{
1. 有 则输出字典序最小的那条
2. 无 则输出"Round trip does not exist."
}
欧拉回路基本概念+判断+求解差点把图建岔劈了
总结
因为在输入的过程中,边的数量和点的数量都不是确定的,所以说我们必须要在输入的过程中记录点的数量以及边的数量,因为点的编号以及边的编号都是连续的,所以说我们可以直接记录点的编号的最大值以及边的编号最大值即可
假如统计出来的边的的最大编号为max_edge,那么说边的最大编号为max_edge,我们从1号点开始,从向便利这个点连向的所有边,如果当前点联想的边没有走过,就标记这条边,然后继续以这条边的另一端为起点继续深搜,中间过程中记录答案,因为每条边最只会被访问一次,所以说复杂度不会很高
ac_code: