Kaleidoscopic Route
Time limit2sMemory limit512 MB
Find a fewest-roads path from city 1 to city n that maximizes the gap between its largest and smallest road colorfulness.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Shortest path, Two pointers
- Solved
- No attempts yet
Problem
Kaleidostan has cities connected by bidirectional roads. The cities are numbered from 1 to . Each road has an integer called colorfulness.
Keanu wants to travel from city 1 to city . He wants a shortest route, meaning the route with the fewest roads. Among all shortest routes, he wants the kaleidoscopic one, meaning the route with the largest possible difference between the maximum and minimum colorfulness of its roads. Help Keanu find such a route.
Input
The first line contains two integers and , the number of cities and the number of roads (; ).
The -th of the following lines contains three integers , , and , the indices of the cities connected by the -th road and its colorfulness (; ; ).
Each pair of cities is connected by at most one road. It is guaranteed that you can travel from any city to any other city using the roads.
Output
In the first line, print a single integer , the number of roads in the required route.
In the second line, print integers , the sequence of cities on the route (; ; ).
Hint

In the example test, the required route consists of 3 roads, and the difference between the maximum and minimum colorfulness of its roads is .