두 끝점이 속한 컴포넌트의 가중치 합이 임계값 이상이 되는 가장 작은 번호의 간선을 더해 컴포넌트를 합치는 과정을 재현하고, 사용된 간선 번호를 순서대로 출력한다.
어려움8유니온 파인드힙그래프분할 정복아직 제출이 없습니다시간 제한5초메모리 제한512 MBWang Xiuhan has an initially empty undirected graph on n vertices.
Each vertex has a weight, which is a non-negative integer.
Also, he has m tuples (ai, bi, si), where 1 ≤ ai, bi ≤ n, ai ≠ bi, and si is a non-negative integer.
After that, he starts the following process:
After the process was completed, a misfortune happened... Someone stole his notepad! Can you help him restore all numbers efficiently?
The first line of input contains two integers n and m: the number of vertices in Xiuhan’s graph and the number of tuples he has (1 ≤ n, m ≤ 300 000).
The second line contains n space-separated integers, w1, w2, . . . , wn: weights of the vertices (0 ≤ wi ≤ 106).
The next m lines contain a description of Xiuhan’s tuples. Each of these lines contains three integers ai, bi, si (1 ≤ ai, bi ≤ n, ai ≠ bi, 0 ≤ si ≤ 106).
On the first line, print one integer: the number of integers Xiuhan wrote in the notepad.
On the next line, you should write all these integers in the order he wrote them.