Under construction

Still being built. Things may change

Connection

Time limit2sMemory limit512 MB

Summary
Decide whether all N vertices can be connected by adding candidate edges while every component keeps its vertex weight sum at least its edge weight sum, and print the edge order.
Level

Medium7 of 10

Topics
Union-find, Greedy, Sorting
Solved
No attempts yet

Problem

There is a graph with NN vertices numbered 1,2,…,N1, 2, \ldots, N. Vertex ii (1≤i≤N1 \leq i \leq N) has a non-negative integer weight aia_i.

Initially, the graph has no edges. You may add undirected edges to the graph. There are MM candidate edges, numbered 1,2,…,M1, 2, \ldots, M. Edge ii (1≤i≤M1 \leq i \leq M) connects vertices xix_i and yiy_i and has a non-negative integer weight ziz_i.

Your goal is to make all vertices connected. To do so, you may repeat the following operation any number of times: choose exactly one candidate edge that has not been added yet and add it to the graph. At every moment, the following condition must hold.

  • For every connected component of the graph, (sum of vertex weights) ≥\geq (sum of edge weights).

Determine whether all vertices can be connected.

Input

NN MM

a1a_1 a2a_2 …\ldots aNa_N

x1x_1 y1y_1 z1z_1

x2x_2 y2y_2 z2z_2

::

xMx_M yMy_M zMz_M

Output

If it is impossible to connect all vertices, print -1 on a single line.

If it is possible, print one way to add edges as follows.

  • On the first line, print the number mm of edges to add (1≤m≤M1 \leq m \leq M).
  • On each of the next mm lines, the kk-th line contains the number iki_k (1≤ik≤M1 \leq i_k \leq M) of the kk-th edge to add.

Constraints

  • 2≤N≤1052 \leq N \leq 10^5
  • aia_i is an integer, 0≤ai≤1090 \leq a_i \leq 10^9
  • 1≤M≤1051 \leq M \leq 10^5
  • 1≤xi<yi≤N1 \leq x_i < y_i \leq N
  • ziz_i is an integer, 0≤zi≤1090 \leq z_i \leq 10^9

Examples3

  1. Example 1

    Input
    4 3
    50 0 0 50
    1 2 0
    2 3 100
    3 4 0
    
    Expected output
    3
    1
    3
    2
    
  2. Example 2

    Input
    2 3
    50 50
    1 2 100
    1 2 101
    1 2 102
    
    Expected output
    1
    1
    
  3. Example 3

    Input
    3 1
    50 50 50
    1 2 100
    
    Expected output
    -1