Logo
(追記) (追記ここまで)

18473번 - Fast Spanning Tree 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB63918611130.579%

문제

Wang 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:

  • If there is no such i that ai and bi lie in different connected components of the graph and (total weight of vertices in the component of ai) + (total weight of vertices in the component of bi) ≥ si, end the process.
  • Otherwise, choose the smallest such i, add an edge between ai and bi to the graph, write this i in the notepad, and repeat the process (but now on the larger graph).

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.

제한

예제 입력 1

5 5
1 4 3 4 0
4 5 5
3 1 1
2 5 2
4 3 1
4 1 4

예제 출력 1

4
2 3 1 4

예제 입력 2

3 5
3 2 2
1 2 6
1 2 6
1 2 3
1 2 6
2 3 6

예제 출력 2

2
3 5

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 2: 300iq Contest 2 F번

Contest > Open Cup > 2019/2020 Season > Stage 1: Grand Prix of Kazan F번

  • 문제를 만든 사람: 300iq
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /