#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
#define iL (1 << 20)
char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
template<typename T>
inline void read(T &a) {
char ch;int sign = 0;
for(ch = gc();!isdigit(ch);ch = gc())
if(ch == '-') sign = 1;
a = ch & 15;
for(ch = gc();isdigit(ch);ch = gc())
a = (a << 3) + (a << 1) + (ch & 15);
if(sign) a = -a;
}
char Out[iL],*iter = Out;
#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
template<typename T>
inline void write(T x,char end = '\n') {
int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
do c[++l] = x % 10,x /= 10; while(x);
while(l) *iter++ = c[l--] + '0';
*iter++ = end;flush();
}
#undef iL
#undef gc
#undef flush
}
using namespace FastIO;
const int N = 3e5 + 5;
typedef long long ll;
#define FI first
#define SE second
#define mkp make_pair
int n,m,w[N];
int A[N],B[N],pw[N],wlim[N]; // lim / 2 ceil
int ufs[N],sze[N];
ll Dec[N],sumw[N];
int find(int x) { return ufs[x] == x ? x : ufs[x] = find(ufs[x]);}
set<pair<ll,int> > warn[N];
// map<int,ll> valw[N];
priority_queue<int,vector<int>,greater<int> > edges;
void Rebuild_warn(int x,ll dta) {
x = find(x);vector<int> V;Dec[x] += dta;
while(warn[x].size() && warn[x].begin() -> FI <= Dec[x]) {
int id = warn[x].begin() -> SE;
V.push_back(id);warn[x].erase(warn[x].begin());
}
for(auto id : V) if(find(A[id]) != find(B[id])) {
int y = find(A[id]) ^ find(B[id]) ^ x;
wlim[id] = max(0ll,pw[id] - Dec[x] - Dec[y]);
// printf("dec:%d,%d\n",id,dta);
if(wlim[id] <= 0) edges.push(id);
else {
int v = (wlim[id] + 1) / 2;
// valw[x][id] = (v + Dec[x]);valw[y][id] = (v + Dec[y]);
warn[x].emplace(v + Dec[x],id);
warn[y].emplace(v + Dec[y],id);
}
}
}
void Merge(int x,int y) {
assert(x != y);
if(sze[x] < sze[y]) swap(x,y);
ll s1 = sumw[x],s2 = sumw[y];
Rebuild_warn(x,s2);Rebuild_warn(y,s1);
sze[x] += sze[y];sumw[x] += sumw[y];
ufs[y] = x;
for(auto [v,id] : warn[y]) {
if(find(A[id]) == find(B[id])) continue;
warn[x].emplace(v,id);
// valw[x][id] = v;
}
warn[y].clear();valw[y].clear();
}
int main() {
read(n);read(m);
for(int i = 1;i <= n;i++)
read(w[i]),sumw[i] = w[i],sze[i] = 1,ufs[i] = i;
for(int i = 1;i <= m;i++) {
read(A[i]);read(B[i]);read(wlim[i]);
pw[i] = wlim[i];
int v = (wlim[i] + 1) / 2;
warn[A[i]].emplace(v,i);
// valw[A[i]][i] = v;
warn[B[i]].emplace(v,i);
// valw[B[i]][i] = v;
}
for(int i = 1;i <= n;i++) Rebuild_warn(i,w[i]);
vector<int> Ans;
while(!edges.empty()) {
int id = edges.top();edges.pop();
// cerr << id << endl;
int x = A[id],y = B[id];
x = find(x);y = find(y);
if(x == y) continue;
Merge(x,y);
Ans.push_back(id);
}
printf("%d\n",Ans.size());
for(auto i : Ans) write(i,' ');
printf("\n");
return 0;
}