Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Ideal Path
Description New labyrinth attraction is open in New Lostland amusement park. The labyrinth consists of n rooms connected by m passages. Each passage is colored into some color c. Visitors of the labyrinth are dropped from the helicopter to the room number 1 and their goal is to get to the labyrinth exit located in the room number _{i}n.Labyrinth owners are planning to run a contest tomorrow. Several runners will be dropped to the room number 1. They will run to the room number n writing down colors of passages as they run through them. The contestant with the shortest sequence of colors is the winner of the contest. If there are several contestants with the same sequence length, the one with the ideal path is the winner. The path is the ideal path if its color sequence is the lexicographically smallest among shortest paths.Andrew is preparing for the contest. He took a helicopter tour above New Lostland and made a picture of the labyrinth. Your task is to help him find the ideal path from the room number 1 to the room number n that would allow him to win the contest.
NoteA sequence ( a, _{1}a, . . . , _{2}a) is lexicographically smaller than a sequence (_{k}b, _{1}b, . . . , _{2}b) if there exists i such that _{k}a < _{i}b, and _{i}a = _{j}b for all _{j}j < i.Input The first line of the input file contains integers n and m βthe number of rooms and passages, respectively (2 <= n <= 100 000, 1 <= m <= 200 000). The following m lines describe passages, each passage is described with three integer numbers: a, _{i}b, and _{i}c β the numbers of rooms it connects and its color (1 <= _{i}a, _{i}b <= n, 1 <= _{i}c <= 10_{i}^{9}). Each passage can be passed in either direction. Two rooms can be connected with more than one passage, there can be a passage from a room to itself. It is guaranteed that it is possible to reach the room number n from the room number 1.Output The first line of the output file must contain k β the length of the shortest path from the room number 1 to the room number n. The second line must contain k numbers β the colors of passages in the order they must be passed in the ideal path.Sample Input 4 6 1 2 1 1 3 2 3 4 3 2 3 1 2 4 4 3 1 1 Sample Output 2 1 3 Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator