Under construction

Still being built. Things may change

Servicing Clients

Time limit1sMemory limit128 MB

Summary
Choose clients whose distance-times-demand costs fit the budget to maximize total priority.
Level

Medium5 of 10

Topics
Dynamic programming, Shortest path
Solved
No attempts yet

Problem

One facility and several clients sit at some of the vertices of a weighted graph G=(V,E)G = (V, E). Every client jj comes with a nonnegative demand djd_j and a nonnegative priority pjp_j that says how important that client is.

The servicing cost of client jj is cj×djc_j \times d_j, where cjc_j is the shortest distance in GG from the facility vertex to the vertex of client jj. In the figure below the servicing cost of client aa is 3×da3 \times d_a, where dad_a is the demand of client aa. The servicing cost of client bb in the same figure is infinite, because no path connects client bb to the facility.

Write a program that picks a subset of the client set whose total servicing cost stays within a nonnegative budget BB and whose total priority is as large as possible.

Input

Your program reads from standard input. The first line contains the number of test cases TT. (1≤T≤201 \le T \le 20)

Each test case starts with a line containing the number of vertices NN of the graph. (1≤N≤1001 \le N \le 100) The vertices are numbered from 00 to N−1N-1, and the facility sits at vertex 00.

The next line contains the number of clients MM. (0≤M≤1000 \le M \le 100) Each of the next MM lines describes one client with three integers: the vertex the client sits at, the demand, and the priority. The vertex number is between 00 and N−1N-1, and the demand and the priority are each between 00 and 100100.

The next line contains the total budget BB. (0≤B≤1000 \le B \le 100)

The next line contains the number of edges LL. (0≤L≤1000 \le L \le 100) Each of the next LL lines describes one edge with three integers: the two vertices the edge joins, then the cost of the edge. The vertex numbers are between 00 and N−1N-1 and the cost is between 00 and 100100. Edges have no direction.

Output

Your program writes to standard output. For each test case, print one line with the total priority of the clients selected for service.

Examples1

  1. Example 1

    Input
    2
    4
    4
    1 5 7
    2 35 20
    3 12 32
    3 10 2
    30
    5
    0 1 5
    0 2 4
    1 3 13
    2 3 4
    1 2 2
    6
    6
    1 3 4
    1 2 4
    3 4 5
    3 2 1
    4 6 3
    5 1 2
    20
    8
    0 1 3
    1 2 5
    2 3 3
    3 4 5
    4 5 10
    0 5 4
    0 3 4
    2 5 6
    
    Expected output
    7
    10