#C6943. Safest Path in a Cave System

    ID: 50759 Type: Default 1000ms 256MiB

Safest Path in a Cave System

Safest Path in a Cave System

You are given an undirected weighted graph representing a cave system. The system consists of n caverns numbered from 0 to n-1, and m bidirectional passages connecting them. Each passage between caverns u and v has an associated difficulty w.

Your task is to determine the safest path from a designated starting cavern to an exit cavern. The safest path is defined as the one with the minimum total difficulty, where the total difficulty is given by the sum of the difficulties along the path:

$$\text{Total Difficulty} = \sum_{(u,v)\in P} w(u,v)$$

If no path exists between the specified caverns, output -1.

inputFormat

The input is read from standard input (stdin).

The first line contains two integers n and m, representing the number of caverns and the number of passages respectively.

This is followed by m lines, each containing three integers u, v and w, indicating that there is a bidirectional passage between cavern u and cavern v with difficulty w.

The last line contains two integers, the starting cavern and the exit cavern.

outputFormat

Output the sequence of caverns (vertices) along the safest path, separated by spaces, to standard output (stdout). If no such path exists, output -1.## sample

5 6
0 1 10
0 2 3
1 2 1
1 3 2
2 3 8
3 4 7
0 4
0 2 1 3 4