DMOPC '20 Contest 7 P5 - Mayors and Tolls

View as PDF

Submit solution


Points: 20
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

You are trying to make a profitable business from toll roads. There are currently M bidirectional roads between N cities, the j-th road connecting cities uj and vj. If you are able to turn the j-th road into a toll road, you will gain a profit of pj.

However, you will only be able to buy a road between cities x and y if you have the approval of both mayors of the two cities. To gain the approval of the mayor of city i, you can pay them a "fee" of cost bi. Once you have paid this "fee," the mayor will do their part to approve all roads neighbouring their city.

Overall, your net profit will be the sum of the profits from the roads minus the sum of the fees. What is the optimal net profit?

Constraints

1N500

0M500

0pj,bi109

1uj,vjN

ujvj

Input Specification

The first line contains 2 integers N and M.

The second line contains N integers bi (1iN).

The next M lines each contain 3 integers uj, vj, and pj.

Output Specification

Output the optimal net profit.

Sample Input

Copy
4 5
8 4 1 2
1 2 3
2 3 5
1 3 4
3 4 2
4 2 2

Sample Output

Copy
2

Comments

There are no comments at the moment.