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, n < 1995. The junctions were independently named by integer numbers from 1 to m, m <= 44. 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 s
John's trip (poj-1041,欧拉回路,字典序最小路径)
最新推荐文章于 2020-09-27 10:01:28 发布
这篇博客讨论了如何帮助Johnny找到城镇中字典序最小的欧拉回路。Johnny希望在拜访所有朋友后回到起点,每个街道只经过一次。文章解释了如何确定是否存在这样的路径,并介绍了使用深搜算法来找到最小的路径序列。如果不存在欧拉回路,程序会输出特定消息。
摘要由CSDN通过智能技术生成