NEWROAD
In a country, there are cities and
roads connecting some of these cities.
It is assumed that the roads are directed, and the road from city u to city v has a (non-negative) length of
.
A new road is to be constructed, and a list of pairs of cities has been proposed that this road could connect.
Each proposed road from city
to city
is accompanied by its respective length
.
Let's consider two given cities, and
.
The task is to choose the proposed road that achieves the maximum reduction in distance from city
to city
.
Input
The first line of input contains five natural numbers separated in pairs by a single space: , the number of cities;
, the number of roads;
, the number of proposed roads;
, the starting city; and
, the destination city.
Each of the next
lines describes a road and contains three natural numbers
,
,
separated in pairs by a space: the starting city
, the ending city
, and its length
.
Each of the next
lines describes a proposed road and contains three natural numbers
,
,
separated in pairs by a space, as before.
The cities, roads, and proposed roads are numbered in ascending order starting from .
Output
The output should consist of a single line containing exactly one integer: the minimum distance from city to city
achieved when selecting the best proposed road.
Note that it is possible that none of the proposed roads will reduce the distance from city to city
.
In this case, none of the proposed roads should be selected, and the result should be the distance between
and
, as in the existing road network.
Constraints
,
,
Every route that does not contain a cycle has a length at most
Execution time limit: 1 sec.
Maximum available memory: 128 MB.
Example of Input - Output
STDIN (newroad.in)
4 4 2 2 4
1 3 10
2 1 7
4 2 9
3 4 8
2 3 15
1 4 12
STDOUT (newroad.out)
19
Comments