IK-WARM Virus
Time limit1.5sMemory limit1024 MB
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 PCs and 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 different PCs and send data containing the virus to them directly. The time needed to send data to PC is .
Given the sequence 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 , , and , the number of PCs, the number of edges, and the maximum number of direct transmissions.
The second line contains integers , separated by spaces, the time needed to send virus-containing data to each PC.
Each of the next lines contains three integers , , and , separated by spaces. This means PC and PC are connected by an edge with transmission time .
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.