#K74952. Total Length of Covered Roads
Total Length of Covered Roads
Total Length of Covered Roads
You are given N intersections and M roads. Each intersection may have a traffic light, represented by 0 (no traffic light) or 1 (has a traffic light). Each road is described by three integers A, B, and L which denote that there is a road connecting intersection A and intersection B with length L.
A road is said to be covered if at least one of its endpoints has a traffic light installed. Your task is to calculate the total length of all roads that are covered.
Formally, if we denote by \( T_i \) a boolean indicator for the i-th road (where \( T_i = 1 \) if the road is covered and \( T_i = 0 \) otherwise), and \( L_i \) is the length of that road, then the answer is:
\[ \text{Total Length} = \sum_{i=1}^{M} T_i \cdot L_i \]inputFormat
The first line contains two integers N and M separated by a space.
The second line contains N integers where each integer is either 0 or 1. The i-th integer indicates whether there is a traffic light at intersection i (1 for yes, 0 for no).
Then follow M lines, each containing three integers A, B, and L, representing a road between intersections A and B with length L.
outputFormat
Output a single integer representing the total length of roads that are covered by at least one traffic light.
## sample4 4
0 1 0 1
1 2 5
2 3 6
3 4 4
4 1 3
18