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. 编写一个名为Test的主类,类中只有一个主方法; 在主方法中定义一个大小为50的一维整型数组,数组名为x,数组中存放着{1, 3,5,…,99}输出这个数组中的所有元素,每输出十个换一行;在主方法中定义一 个大小为10*10的二维字符型数组,数组名为y,正反对角线上存的是‘*’,其余 位置存的是‘#’;输出这个数组中的所有元素。

    package liu0915; import java.util.Random; public class Test0915sz { public static void main(String[] ...

  2. hdu Train Problem I

    这道题是道简单的栈模拟题,只要按照真实情况用栈进行模拟即可: #include<stdio.h> #include<string.h> #include<stack> ...

  3. Web服务器上可能被包含或被请求的不同脚本源代码文件

    Web服务器上可能被包含或被请求的不同脚本源代码文件的大致数量(建议值为1024~4096). ; 如果你不能确定,则设为 0 :此设定主要用于拥有数千个源文件的站点. apc.optimizatio ...

  4. 三层架构实例 VB.NET版

    三层实例 首先发现感慨,对于三成这块,用到都是一些面向对象的特征,尤其是对象的实例化.如果你不是很注意的话,那么,你就会一头雾水,就像我一样,慢慢的雾里看花,最后也是走出来的,不过用的事件是相当的. ...

  5. Powershell变量的类型

    Powershell 默认支持的.NET类型如下:   [order], [pscustomobject], [array], [bool], [byte], [char], [datetime], ...

  6. SQLServer组件

    1.客户端 2.协议层 3.查询处理器 4.存储引擎 5.数据库操作系统 如下图:

  7. Ubuntu下配置C/C++开发环境

    在 Ubuntu 下配置 C/C++ 开发环境 转自:白巴的临时空间 Submitted by 白巴 on 2009-04-27 19:52:12. 学习笔记 虽然 Ubuntu 的版本已经是9.04 ...

  8. 20145225 实验四《Andoid开发基础》

    实验内容 搭建Android环境 运行Android 修改代码,能输出学号 实验步骤 安装Android Studio 安装Android的SDK 运行Andriod Studio并在模拟手机上显示自 ...

  9. Ubuntu 14.04 为 root 帐号开启 SSH 登录

    1. 修改 root 密码 sudo passwd root 2. 以其他账户登录,通过 sudo nano 修改 /etc/ssh/sshd_config : xxx@ubuntu14:~$ su ...

  10. P1017 进制转换

    模拟水题,直接上代码 #include <bits/stdc++.h> using namespace std; const int maxn = 100000; int main() { ...