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, 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 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

1 2 1
2 3 2
3 1 6
1 2 5
2 3 3
3 1 4
0 0
1 2 1
2 3 2
1 3 3
2 4 4
0 0
0 0

Sample Output

1 2 3 5 4 6
Round trip does not exist.

POJ 1041问题描述的更多相关文章

  1. poj 1041(欧拉回路+输出字典序最小路径)

    题目链接:http://poj.org/problem?id=1041 思路:懒得写了,直接copy吧:对于一个图可以从一个顶点沿着边走下去,每个边只走一次,所有的边都经过后回到原点的路.一个无向图存 ...

  2. [POJ 1041] John's Trip

    [题目链接] http://poj.org/problem?id=1041 [算法] 欧拉回路[代码] #include <algorithm> #include <bitset&g ...

  3. poj 1041 John's trip——欧拉回路字典序输出

    题目:http://poj.org/problem?id=1041 明明是欧拉回路字典序输出的模板. 优先队列存边有毒.写跪.学习学习TJ发现只要按边权从大到小排序连边就能正常用邻接表了! 还有一种存 ...

  4. POJ 1528问题描述

    Description From the article Number Theory in the 1994 Microsoft Encarta: ``If a, b, c are integers ...

  5. POJ 1039问题描述

    Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic li ...

  6. POJ 1035题目描述

    Description You, as a member of a development team for a new spell checking program, are to write a ...

  7. POJ 1032问题描述

    Description New convocation of The Fool Land's Parliament consists of N delegates. According to the ...

  8. POJ 1028题目描述

    Description Standard web browsers contain features to move backward and forward among the pages rece ...

  9. poj 1041 John's trip 欧拉回路

    题目链接 求给出的图是否存在欧拉回路并输出路径, 从1这个点开始, 输出时按边的升序输出. 将每个点的边排序一下就可以. #include <iostream> #include < ...

随机推荐

  1. Oracle--10(ROW_NUMBER() OVER)

    一.定义 语法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN) 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这 ...

  2. WPF之拖动项滚动条自滚动(当拖动项到达高度的边界时候滚动条自己可以上下滚动)

    参考 http://www.cnblogs.com/ListenFly/p/3281997.html Point svPoint = e.GetPosition(sv); if (sv.ActualH ...

  3. IT电子书网站下载

    https://www.gitbook.com/ http://www.it-ebooks.info/ http://www.fenby.com/courses/sections/kuai-su-ka ...

  4. Ctrl+Shift+F12切换最大化编辑器

    常用快捷键(keymaps:Default情况下) Esc键编辑器(从工具窗口) F1帮助千万别按,很卡! F2(Shift+F2)下/上高亮错误或警告快速定位 F3向下查找关键字出现位置 F4查找变 ...

  5. java---一元二次方程练习

    public class wu{ public static void main(String[] args){ int a = 2,b = 1, c = 0,d = b*b-4*a*c if (a ...

  6. [DX11] Introduction

    http://www.cnblogs.com/clayman/archive/2011/10/18/2216889.html The Beauty of DirectX 11

  7. md5只是用来签名,签名的作用是保证数据完整不会被破坏而已。签名和加密是两回事

    md5只是用来签名,签名的作用是保证数据完整不会被破坏而已,多一个sign标签,sign的值就是md5生成的字符串.签名和加密是两回事

  8. 理解 Python 中的 *args 和 **kwargs

    Python是支持可变参数的,最简单的方法莫过于使用默认参数,例如: def test_defargs(one, two = 2): print 'Required argument: ', one ...

  9. TP中不区分大小写__APP__和__URL__的注意事项

    控制器命名为 : AuthGroupAction.class.php 问题 : 在控制器跳转中.如果模板跳转时地址的大小写错了..就会报无法加载模块 报错 : 无法加载模块:Authgroup 解决办 ...

  10. Flink - DataStream

    先看例子, final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); D ...