Wakanda Forever

aaman007 Intra Metropolitan Univer...
Limits 1s, 512 MB

We all know that Thanos has erased half of the population of the universe. Earth’s population was also decreased from 7 billion to 3.5 billion.

In Wakanda there are n cities (numbered 1 to nn) connected by m bidirectional roads.

As T’Challa was disintegrated by the Thanos snap, M’Baku is the new king of Wakanda. M’Baku wants to close some of the roads of Wakanda because the population of some cities were erased completely and some roads are unnecessary.

As you are M’Baku‘s friend, he asked you to help him to minimize the number of roads necessary so that all cities with people are connected and the total length of all active roads will be minimized.

Note that, it is possible that by closing some roads, Wakanda may not be connected anymore. In that case, M’Baku will need to create some new roads each having length dd.

If a city doesn’t have any people left on it, all roads connected to it should be closed.

Input

The first line of the input contains three integers, nn, mm and dd (2n1052 ≤ n ≤ 10^5, n1m3105n-1 ≤ m ≤ 3 * 10^5, 1d1001 ≤ d ≤ 100), the number of cities currently in Wakanda, the number of roads and the lengths of new roads.

The second line contains n integers, denoting number of people a[i]a[i] (0a[i]1000 ≤ a[i] ≤ 100) in city i after the disintegration.

The next m lines each contain three integers, uu, vv and ww (1u,vn1 ≤ u, v ≤ n, 1w1001 ≤ w ≤ 100), the road end-points and lengths.

Output

Print the total length of all active roads after you help M’Baku.

Sample

InputOutput
5 6 100
100 100 5 0 10
1 2 3
1 4 1
1 3 3
3 4 1
2 4 5
4 5 1
106

Submit

Login to submit.

Statistics

84% Solution Ratio
prodip_bsmrstuEarliest, Apr '19
cloud007Fastest, 0.1s
riyad000Lightest, 3.9 MB
zishan044Shortest, 913B
Toph uses cookies. By continuing you agree to our Cookie Policy.