Under construction

Still being built. Things may change

Fast Spanning Tree

Time limit5sMemory limit512 MB

Summary
Given weighted vertices and m conditional edges (a, b, s), find the indices of the edges added in order, where an edge is added if it joins two components whose total weight is at least s.
Level

Hard8 of 10

Topics
Union-find, Divide and conquer, Sorting
Solved
No attempts yet

Statement

Wang Xiuhan has an initially empty undirected graph on nn vertices.

Each vertex has a weight, which is a non-negative integer.

He also has mm tuples (ai,bi,si)(a_i, b_i, s_i), where 1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i, and sis_i is a non-negative integer.

After that, he starts the following process:

  • If there is no ii such that aia_i and bib_i lie in different connected components and (total weight of the component of aia_i) + (total weight of the component of bib_i) ≥si\ge s_i, the process ends.
  • Otherwise, he chooses the smallest such ii, adds an edge between aia_i and bib_i, writes ii in the notepad, and repeats the process on the larger graph.

The process is finished, and then a misfortune happens: someone stole his notepad! Can you help him restore all the numbers efficiently?

Input

The first line contains two integers nn and mm: the number of vertices in the graph and the number of tuples (1≤n,m≤300 0001 \le n, m \le 300\,000).

The second line contains nn space-separated integers w1,w2,…,wnw_1, w_2, \ldots, w_n, the weights of the vertices (0≤wi≤1060 \le w_i \le 10^6).

Each of the next mm lines contains three integers aia_i, bib_i, sis_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i, 0≤si≤1060 \le s_i \le 10^6).

Output

On the first line, print the number of integers written in the notepad. On the next line, print all these integers in the order he wrote them.

Examples2

  1. Example 1

    Input
    5 5
    1 4 3 4 0
    4 5 5
    3 1 1
    2 5 2
    4 3 1
    4 1 4
    
    Expected output
    4
    2 3 1 4
    
  2. Example 2

    Input
    3 5
    3 2 2
    1 2 6
    1 2 6
    1 2 3
    1 2 6
    2 3 6
    
    Expected output
    2
    3 5