Under construction

Still being built. Things may change

IK-WARM Virus

Time limit1.5sMemory limit1024 MB

Summary
Given a PC network with edge transmission times and per-PC hack costs, find the minimum total cost to infect every PC using at most K direct hacks.
Level

Medium7 of 10

Topics
Minimum spanning tree, Binary search, Graph, Greedy
Solved
No attempts yet

Problem

Oh Ik-jun, a hacker in the 영과일 organization, plans to infect a PC with his newly developed virus 'IK-WARM' and then have the virus spread to every PC on the network.

The network has NN PCs and MM network edges, forming an undirected graph. Each edge has a unique transmission time, which is the time needed to send data between the two PCs it connects. The two PCs in each transmission are different, and any two PCs have at most one direct connection.

A PC infected with the virus can send data containing the virus to its neighbors through the network edges, and a PC that receives such data is infected immediately.

Oh Ik-jun can hack up to KK different PCs and send data containing the virus to them directly. The time needed to send data to PC ii is aia_i.

Given the sequence aa and the network information, find the minimum total transmission time needed to infect every PC in the network that has no infected PC at the start. Here, the total transmission time is the sum of the times spent sending data to each PC.

Input

The first line contains three integers NN, MM, and KK, the number of PCs, the number of edges, and the maximum number of direct transmissions. (1≤N≤1 000; 0≤M≤min⁡(N(N−1)2, 100 000); 1≤K≤N)(1 \leq N \leq 1\,000;\ 0 \leq M \leq \min(\frac{N(N-1)}{2},\ 100\,000);\ 1 \leq K \leq N)

The second line contains NN integers aia_i, separated by spaces, the time needed to send virus-containing data to each PC. (1≤ai≤100 000; 1≤i≤N)(1 \leq a_i \leq 100\,000;\ 1 \leq i \leq N)

Each of the next MM lines contains three integers XX, YY, and ZZ, separated by spaces. This means PC XX and PC YY are connected by an edge with transmission time ZZ. (1≤X,Y≤N; 1≤Z≤100 000)(1 \leq X, Y \leq N;\ 1 \leq Z \leq 100\,000)

Output

Print the minimum total transmission time needed to infect every PC on the network on the first line. If the virus cannot spread to the entire network, print -1.

Examples2

  1. Example 1

    Input
    7 6 2
    1 3 2 1 4 3 2
    1 2 2
    1 3 2
    3 4 3
    3 2 1
    5 6 4
    5 7 2
    
    Expected output
    15
    
  2. Example 2

    Input
    5 3 1
    3 2 5 7 1
    1 2 3
    3 2 8
    4 5 4
    
    Expected output
    -1