Omnes Viae Yokohamam Ducunt?

시간 제한3초메모리 제한2048 MB

요약
각 간선의 취약도와 도시 1에서 분리되는 도시들의 중요도 합을 곱한 값의 총합을 최소로 하는 신장 트리를 고른다.
난이도

어려움10점 중 8점

유형
그래프, 최소 신장 트리, 그리디, DFS
정답자
아직 제출이 없습니다

문제

“Omnes viae Romam ducunt” is an old Latin proverb meaning “all roads lead to Rome.” It is still desirable to have access to the capital from all the regions of a country.

The Kingdom of Kanagawa has a number of cities, including the capital city, Yokohama. The Ministry of Transport of the Kingdom is now planning to construct a highway network, connecting all those cities.

There are a number of candidate highway segments, each of which directly connects two cities. A highway network is a set of highway segments chosen from the candidates. The following are required for the highway network.

  • All the cities should be connected via highway segments in the network, directly or indirectly.
  • To save the budget, the minimum number of segments should be chosen. In other words, the highway network should not be redundant; the path connecting any pair of cities should be unique.

The highway network should be made resistant to natural disasters, with the limited budget. The emphasis is placed on accessibility to and from the capital city, Yokohama. As the network is planned to be non-redundant, when one segment becomes unavailable due to a natural disaster, some of the cities become inaccessible from Yokohama.

We want to minimize the total risk severity, defined as follows.

The cities in the Kingdom have different populations and economic scales, based on which, the cities are assigned certain significance values. Given a highway network, the damage suffered from a natural disaster on a single segment in the network is estimated by the sum of the significance values of such cities made inaccessible from Yokohama.

Vulnerabilities to natural disasters are assessed for all the candidate segments. The risk severity of a segment is calculated as the product of its estimated damage and vulnerability. The total risk severity of the network is estimated as the sum of the risk severities of all the segments in the network.

Your task is to determine the minimum total risk severity by appropriately designing the highway network.

입력

The input consists of a single test case of the following format.

nn mm

p_1p\_1 ⋯\cdots p_np\_n

u_1u\_1 v_1v\_1 q_1q\_1

⋮\vdots

u_mu\_m v_mv\_m q_mq\_m

The first two integers nn and mm (2≤n≤1052 ≤ n ≤ 10^5, 1≤m≤3×1051 ≤ m ≤ 3 \times 10^5) describe the numbers of cities and highway segment candidates, respectively. The cities are numbered from 11 to nn, with Yokohama numbered 11. The second line contains nn integers p_1,…,p_np\_1, \dots , p\_n, where each p_ip\_i (1≤p_i≤10001 ≤ p\_i ≤ 1000) represents the significance value assigned to the city numbered ii.

The following mm lines describe the candidate highway segments. The jj-th line of them contains three integers u_ju\_j, v_jv\_j, and q_jq\_j (1≤u_j<v_j≤n1 ≤ u\_j < v\_j ≤ n, 1≤q_j≤1061 ≤ q\_j ≤ 10^6), meaning that the segment candidate connecting cities numbered u_ju\_j and v_jv\_j has the vulnerability q_jq\_j. Each pair (u_j,v_j)(u\_j , v\_j ) appears at most once in the input.

It is guaranteed that one or more highway networks that connect all the cities can be designed using some of these segments.

출력

Output a line containing the minimum possible total risk severity.

예제2

  1. 예제 1

    입력
    3 3
    1 2 3
    1 2 2
    2 3 3
    1 3 4
    
    예상 출력
    16
    
  2. 예제 2

    입력
    5 7
    2 6 7 7 10
    1 5 8
    1 4 6
    3 4 9
    2 3 6
    2 4 7
    1 3 4
    4 5 4
    
    예상 출력
    210