TRAFFICN - Traffic Network

The city traffic network consists of n nodes numbered from 1 to n and m one-way roads connecting pairs of nodes. In order to reduce the length of the shortest path between two different critical nodes s and t, a list of k two-way roads are proposed as candidates to be constructed. Your task is to write a program to choose one two-way road from the proposed list in order to minimize the resulting shortest path between s and t.


The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.

For each data set, the first line contains five positive integers n (n ≤ 10 000), m (m ≤ 100 000), k (k < 300), s (1 ≤ s ≤ n), t (1 ≤ t ≤ n) separated by space. The ith line of the following m lines contains three integers di, ci, li separated by space, representing the length li ( 0< li ≤ 1000) of the ith one-way road connecting node di to ci. The jth line of the next k lines contains three positive integers uj, vj and qj (qj ≤ 1000) separated by space, representing the jth proposed two-way road of length qj connecting node uj to vj.


For each data set, write on one line the smallest possible length of the shortest path after building the chosen one two-way road from the proposed list. In case, there does not exist a path from s to t, write -1.


Sample Input
4 5 3 1 4
1 2 13
2 3 19
3 1 25
3 4 17
4 1 18
1 3 23
2 3 5
2 4 25	

Sample Output

hide comments
surayans tiwari( 2016-07-04 20:44:00

don't just blindly take 1061109567 , u can take any value greater than 200000000 because the maximum value of cost can reach 100000*1000 = 100000000 so to be on safe side take value greater than 200000000 , i took 300000000 and got ac!

aspro: 2016-06-22 06:29:50

nice question.....comments helped

Last edit: 2016-06-22 06:30:22
ajay_5097: 2016-06-03 17:26:58

WTF .. Used INT_MAX got Too many WAs
Used 1061109567 got AC !

danuwfna: 2016-06-02 15:19:00

@ankurverma1994 it's not weird, because without calculated value for INF, at every iteration you make an computation.

ankurverma1994: 2016-05-29 13:57:44

Using Integer.MAX_VALUE/3 as infinity getting TLE. But putting infinity as calculated value of Integer.MAX_VALUE/3 getting AC in Java. Something weird. :(

ankurverma1994: 2016-05-29 13:49:46

Too much optimization needed in Java after using Fast I/O. Till now only AC Java solution is mine :D

Shikhar: 2016-04-26 18:18:20

Very misleading problem statement .
There can be cases when no road is chosen.
Cost me 2 WA :(

dev: 2016-03-25 15:22:26

Good dijkstra prob!
29th Fastest solution :)

Sumit Vohra: 2016-01-24 17:40:26

learned something new

Vikrant Singh: 2015-08-04 19:14:08

1061109567 = AC !

Added by:Duc
Time limit:0.140s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Regional, Ho Chi Minh City 2008