Under construction

Still being built. Things may change

Fortification

Time limit2sMemory limit1024 MB

Summary
Given fortification times for locations and roads that flood at set times, find the most locations that can be fortified on a round trip starting and ending at location 1.
Level

Medium7 of 10

Topics
Graph, Shortest path, Greedy
Solved
No attempts yet

Statement

A hurricane is approaching. Critical buildings and infrastructure must be fortified by adding extra supplies, installing power generators, or placing sandbags and other flood barriers. Each fortification takes time, and roads flood quickly, so not every plan may be finished in time. Find the maximum number of plans that can be finished under the road flooding constraints.

You are given a list of locations ii that need fortification, and for each location the time tit_i it takes to fortify. A road network connects the locations. For each road, you are given the time it floods. A road can be used up to and including that time, but not later. Driving is instantaneous, since it is fast compared to fortification. Your route must start and end at location 1, the safe depot for the maintenance vehicle.

Input

The first line contains KK (1≤K≤1001 \le K \le 100), the number of data sets. Each data set begins with two integers nn and rr (1≤n≤10001 \le n \le 1000, 0≤r≤1000000 \le r \le 100000), the number of locations to fortify and the number of roads.

The next line contains nn integers tit_i (0≤ti≤10000000 \le t_i \le 1000000), the time to fortify location ii.

Each of the next rr lines contains three integers aja_j, bjb_j, fjf_j (1≤aj,bj≤n1 \le a_j, b_j \le n, 0≤fj≤10000000 \le f_j \le 1000000). Road jj connects aja_j and bjb_j, can be used in both directions, and floods at time fjf_j. The same pair of endpoints may appear more than once.

Output

For each data set, print Data Set x: on its own line, where xx is the data set number. Then print the maximum number of locations that can be fortified under the flooding constraints. Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    1
    6 8
    6 1 1 4 3 4
    1 3 1
    3 2 1
    6 5 8
    1 2 1
    3 4 6
    2 4 5
    1 5 8
    6 1 5
    
    Expected output
    Data Set 1:
    4