CF1095F Make It Connected

Description

You are given an undirected graph consisting of $ n $ vertices. A number is written on each vertex; the number on vertex $ i $ is $ a_i $ . Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $ x $ and $ y $ is $ a_x + a_y $ coins. There are also $ m $ special offers, each of them is denoted by three numbers $ x $ , $ y $ and $ w $ , and means that you can add an edge connecting vertices $ x $ and $ y $ and pay $ w $ coins for it. You don't have to use special offers: if there is a pair of vertices $ x $ and $ y $ that has a special offer associated with it, you still may connect these two vertices paying $ a_x + a_y $ coins for it. What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first example it is possible to connect $ 1 $ to $ 2 $ using special offer $ 2 $ , and then $ 1 $ to $ 3 $ without using any offers. In next two examples the optimal answer may be achieved without using special offers.