F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Ideal Path

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2369    Accepted Submission(s): 432


Problem 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 ci. 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 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.
Note
A sequence (a1, a2, ¡­, ak) is lexicographically smaller than a sequence (b1, b2, ¡­, bk) if there exists i such that ai < bi, and aj = bj for all j < i.
 

Input
The input begins with an integer T. The next T blocks each represents a case. The first line of each case 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: ai, bi, and ci - the numbers of rooms it connects and its color (1 ¡Ü ai, bi ¡Ü n, 1 ¡Ü ci ¡Ü 109). 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
For each case, the first line of the output 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
1 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
 

Author
Andrey Stankevich
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 11:04:39, Gzip enabled