码农谷 > 问答 > 编程题 > Run for beer

Run for beer

提问者: 老码农     发布时间:2017-01-11     浏览:5     回复:0     悬赏:0.0 谷币

People in BubbleLand like to drink beer. Little do you know, beer here is so good and strong that every time you drink it your speed goes 10 times slower than before you drank it.

Birko lives in city Beergrade, but wants to go to city Beerburg. You are given a road map of BubbleLand and you need to find the fastest way for him. When he starts his journey in Beergrade his speed is 1. When he comes to a new city he always tries a glass of local beer, which divides his speed by 10.

The question here is what the minimal time for him to reach Beerburg is. If there are several paths with the same minimal time, pick the one that has least roads on it. If there is still more than one path, pick any.

It is guaranteed that there will be at least one path from Beergrade to Beerburg.

Input

The first line of input contains integer N — the number of cities in Bubbleland and integer M — the number of roads in this country. Cities are enumerated from 0 to N - 1, with city 0 being Beergrade, and city N - 1 being Beerburg. Each of the following M lines contains three integers a, b (a ≠ b) and len. These numbers indicate that there is a bidirectional road between cities a and b with length len.

  • 2 ≤ N ≤ 105
  • 1 ≤ M ≤ 105
  • 0 ≤ len ≤ 9
  • There is at most one road between two cities
Output

The first line of output should contain minimal time needed to go from Beergrade to Beerburg.

The second line of the output should contain the number of cities on the path from Beergrade to Beerburg that takes minimal time.

The third line of output should contain the numbers of cities on this path in the order they are visited, separated by spaces.


输入样例:
8 10
0 1 1
1 2 5
2 7 6
0 3 2
3 7 3
0 4 0
4 5 0
5 7 2
0 6 0
6 7 7

输出样例:
32
3
0 3 7

我要挑战
其他解答 共0条
 
温馨提示:本问答中心的任何言论仅代表发言者个人的观点,与码农谷立场无关。请对您的言论负责,遵守中华人民共和国有关法律、法规。如果您的言论违反码农谷问答中心的规则,将会被删除。
验证码: 看不清?点击图片更换    

关注码农谷微信
专家推荐
老码农     向TA提问 最佳答案:67
冰点     向TA提问 最佳答案:28
itner     向TA提问 最佳答案:11
关于我们   |   免责声明   |   联系我们   |   网站地图   |   HR交流群   |   学生交流群   |   教师交流群

码农谷   版权所有 © 2015-2017   湘ICP备16018319号-1