The Demon Towers (MEDIUM)
Practice
1 (1 votes)
Medium
Problem
56% Success 73 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Adventure of our mysterious hero Sin continues after saving the queen. :
This time Sin has has to pursue the wizard who abducted the queen. The wizard lives in an island far from the kingdom.
There are n Demon towers between the Kingdom and the island. In order to reach the wizard Sin needs to Destroy all the Demon towers in the way.
Towers are connected to each other via mysterious energy.
The ithtower has power ti.All pairs are unique. In order to destroy a Demon tower ti the amount of energy Sin has to spend is equivalent to the sum of the powers of the tower connected to the tower ti.
Since Sin is too badly injured from the previous battle, so he cannot use up much of his strength or he may die.
Help Sin to calculate the minimum amount of energy he has to spend in order to destroy all the towers.

Constraints
1<=n,m<=105
1<=u,v<=n
0<=pi<=109

Input
the first line contains n and m denoting the number of towers and connections between them.
The next line contains n integers denoting the power of each tower Pi.
The next m line contains u and v denoting that tower u is connected with tower v.

Output
Print minimum strength required to destroy the base.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
MathematicsMediumapprovedMathematicsMathamatics
Points:30
10 votes
Tags:
MediumBasic MathMathematicsMathematics
Points:30
46 votes
Tags:
GeometryImplementationOpenAlgorithmsApprovedMedium