CF1095F.Make It Connected
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is ai . 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 ax+ay 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 ax+ay 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.
输入格式
The first line contains two integers n and m ( 1≤n≤2⋅105 , 0≤m≤2⋅105 ) — the number of vertices in the graph and the number of special offers, respectively.
The second line contains n integers a1,a2,…,an ( 1≤ai≤1012 ) — the numbers written on the vertices.
Then m lines follow, each containing three integers x , y and w ( 1≤x,y≤n , 1≤w≤1012 , x=y ) denoting a special offer: you may add an edge connecting vertex x and vertex y , and this edge will cost w coins.
输出格式
Print one integer — the minimum number of coins you have to pay to make the graph connected.
输入输出样例
输入#1
3 2 1 3 3 2 3 5 2 1 1
输出#1
5
输入#2
4 0 1 3 3 7
输出#2
16
输入#3
5 4 1 2 3 4 5 1 2 8 1 3 10 1 4 7 1 5 15
输出#3
18
说明/提示
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.