CF95C.Volleyball

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has nn junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can have different lengths.

Initially each junction has exactly one taxi standing there. The taxi driver from the ii -th junction agrees to drive Petya (perhaps through several intermediate junctions) to some other junction if the travel distance is not more than tit_{i} meters. Also, the cost of the ride doesn't depend on the distance and is equal to cic_{i} bourles. Taxis can't stop in the middle of a road. Each taxi can be used no more than once. Petya can catch taxi only in the junction, where it stands initially.

At the moment Petya is located on the junction xx and the volleyball stadium is on the junction yy . Determine the minimum amount of money Petya will need to drive to the stadium.

输入格式

The first line contains two integers nn and mm ( 1<=n<=1000,0<=m<=1000)1<=n<=1000,0<=m<=1000) . They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 11 to nn , inclusive. The next line contains two integers xx and yy ( 1<=x,y<=n1<=x,y<=n ). They are the numbers of the initial and final junctions correspondingly. Next mm lines contain the roads' description. Each road is described by a group of three integers uiu_{i} , viv_{i} , wiw_{i} ( 1<=ui,vi<=n,1<=wi<=1091<=u_{i},v_{i}<=n,1<=w_{i}<=10^{9} ) — they are the numbers of the junctions connected by the road and the length of the road, correspondingly. The next nn lines contain nn pairs of integers tit_{i} and cic_{i} ( 1<=ti,ci<=1091<=t_{i},c_{i}<=10^{9} ), which describe the taxi driver that waits at the ii -th junction — the maximum distance he can drive and the drive's cost. The road can't connect the junction with itself, but between a pair of junctions there can be more than one road. All consecutive numbers in each line are separated by exactly one space character.

输出格式

If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

输入输出样例

  • 输入#1

    4 4
    1 3
    1 2 3
    1 4 1
    2 4 1
    2 3 5
    2 7
    7 2
    1 2
    7 7
    

    输出#1

    9
    

说明/提示

An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles.

首页