Under construction

Still being built. Things may change

Detour

Time limit2sMemory limit512 MB

Summary
In a graph with unique shortest paths to node 1, a sign at each node points along its shortest path; find a simple 0-to-1 path never taking a signed road, minimizing length then lexicographic order.
Level

Medium7 of 10

Topics
Graph, Shortest path, BFS, Greedy
Solved
No attempts yet

Problem

You travel from Delft to Amsterdam by bus. Every intersection along the way carries a traffic sign that points in the direction of the shortest route to Amsterdam. This bus never takes the road a sign points to.

Decide whether such a bus route exists. A bus route starts in Delft, ends in Amsterdam, and never visits the same intersection twice. At every intersection of the route other than Amsterdam, the road the bus takes next must differ from the road the sign at that intersection points to.

The road network is a simple connected undirected graph, and the shortest route to Amsterdam is unique from every intersection. The sign at an intersection points to the first road of that route.

Input

The first line has two integers, the number of intersections nn (2≤n≤1052 \le n \le 10^5) and the number of undirected roads mm (1≤m≤1061 \le m \le 10^6). Intersections are numbered 00 to n−1n-1. Delft is intersection 00 and Amsterdam is intersection 11.

Each of the next mm lines describes one road with three integers aia_i, bib_i (0≤ai,bi<n0 \le a_i, b_i < n, ai≠bia_i \ne b_i) and did_i (0≤di≤5000000 \le d_i \le 500000). The road connects intersection aia_i and intersection bib_i, and its length is did_i in either direction.

Output

If no route satisfies the requirement, print impossible.

Otherwise print the route on one line. Print the number of intersections kk on the route, then the intersection numbers p0,…,pk−1p_0, \dots, p_{k-1} in the order the bus passes them, where p0=0p_0 = 0 and pk−1=1p_{k-1} = 1.

Several routes can satisfy the requirement. Print the one that passes through the fewest intersections. If several routes tie, print the one whose sequence p0,…,pk−1p_0, \dots, p_{k-1} is lexicographically smallest.

Examples3

  1. Example 1

    Input
    4 5
    0 2 5
    2 1 5
    0 3 10
    3 1 20
    3 2 5
    
    Expected output
    3 0 3 1
    
  2. Example 2

    Input
    4 3
    0 1 10
    1 2 20
    2 3 30
    
    Expected output
    impossible
    
  3. Example 3

    Input
    7 9
    0 1 800
    6 2 300
    2 3 75
    3 4 80
    4 5 50
    4 1 100
    1 6 35
    0 2 120
    0 3 100
    
    Expected output
    2 0 1