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.

Input

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.

Output

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.

Example

Sample Input
1
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
35

Được gửi lên bởi:Jimmy
Ngày:2009-01-04
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:ACM Regional, HCMC 2008 Tic Tac Toe

hide comments
2017-03-11 09:40:52
ngày ấy thì chê đề bài ngu h lại thấy mk ngu :) ac sau 1 năm
2017-02-03 02:32:52
cái nì có cần xài heap ko vại? :v
2016-10-01 17:16:45
vc cái đề bài như cái đầu bài
2016-07-10 12:41:20 THK6
đúng 15 lần mới AC :'(
2016-05-29 13:49:03 Lê Thanh Phú
d[i]=2e9 --> WA
d[i]=1e9 --> AC
2016-05-22 05:45:00
Đề bài yêu cầu chọn 1 đoạn đường 2 chiều để thêm vào nhưng không có nghĩa là bắt buộc phải dùng nó :3
2016-05-22 03:19:11
Stupid bugs, f*** you ~,~
2016-02-25 10:10:59
lỗi NZEC là j vậy mấy anh?
2015-12-25 21:53:45 Con Bò Huyền Thoại
@dragon6426: đọc lại đề đi bạn nhé
2015-12-01 13:49:47
tất nhiên là từ s đến t rồi.
t đến s thì 4 1 18 là nhanh nhất chứ cần gì tới 35
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.