The Shortest Path#4856

The Shortest Path

2 seconds
128 megabytes
Medium

Given an undirected weighted graph, find the shortest path between two specified vertices.

\InputFileThe first line contains two positive integers and (n \leq 2000, m \leq 50000) — the number of vertices and edges in the graph.

The second line contains two integers and (1 \leq s, f \leq n, s \neq f) — the numbers of the start and end vertices between which you must find the shortest path.

Each of the next lines contains three integers b_i, e_i, and w_i (1 \leq b_i, e_i \leq n, 0 \leq w_i \leq 10^5) — the endpoints and weight of the -th edge.

\OutputFileOn the first line, print one integer — the length of the shortest path between vertices and .

On the second line, print all the vertices on the shortest path from to in order, separated by spaces.

If there is no path from to , print -1.

prb4856.gif

Examples

Example 1

Loading
Loading