Island

0

0 votes
Graph Theory, Graph, Minimum spanning tree, Algorithms, Medium
Problem

There are  islands. There can be a maximum of two bridges(both bidirectional) connecting a pair of islands. Every bridge has a maintenance cost. You have to reduce the cost of maintenance as much as possible by breaking some of these bridges because a broken bridge does not need any maintenance. The bridges should be broken in such a way that any pair of islands should be reachable from each other. What is the maximum cost which can be reduced?

You are given the maintenance cost of each bridge in the form of array. . is the maintenance cost of one of the bridges between and islands.

Note

  • for
  • and are the maintenance cost of different bridges for
  • If , then it is not a bridge

Input format

  • First line:  denoting the total number of islands
  • ​​​​​​ lines follow:
    •   line:  space-separated integers denoting the  row of Arr

Output format

  • Print the answer to the problem.

Constraints

Maintenance cost of each bridge

 

Sample Input
2
0 3
10 0
Sample Output
10
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are two bridges between island 1 and 2 of maintenance cost . So, the bridge with cost can be broken. So maintenance cost of can be reduced.

Editor Image

?