#C8046. Minimum Package Delivery Time

    ID: 51985 Type: Default 1000ms 256MiB

Minimum Package Delivery Time

Minimum Package Delivery Time

You are given n warehouses and m bidirectional roads connecting them. Each road connects two different warehouses and has an associated travel time. Your task is to determine the minimum travel time required to deliver a package from a specified start warehouse to a given end warehouse.

If there is no possible route from the start to the destination, output -1.

The problem can be formulated as finding the shortest path in a weighted graph. The weight of an edge represents the travel time between two warehouses. A popular algorithm for solving this is Dijkstra's algorithm. In mathematical terms, if we denote the distance from the start node to any node v as \( d(v) \), then the distance update is given by:

[ d(v) = \min\left(d(v),; d(u) + t_{uv} \right) ]

where \( t_{uv} \) is the travel time between nodes \( u \) and \( v \).

inputFormat

The first line contains two integers n and m representing the number of warehouses and the number of roads respectively.

The next m lines each contain three integers u, v, and t, indicating that there is a road between warehouse u and warehouse v with travel time t.

The last line contains two integers start and end: the starting warehouse and the destination warehouse.

outputFormat

Output a single integer representing the minimum travel time from the start to the destination warehouse. If there is no valid route, output -1.

## sample
5 6
1 2 4
1 3 2
2 3 5
2 4 10
3 5 3
4 5 7
1 5
5