1 uses math;
2 var fa,a,b,c,w:array[0..120000] of longint;
3 i,j,n,m,ans:longint;
4 function find(x:longint):longint;
5 begin
6 if fa[x]<>x then fa[x]:=find(fa[x]);
7 exit(fa[x]);
8 end;
9
10 procedure sort(l,r:longint);
11 var i,j,x,y:longint;
12 begin
13 i:=l;j:=r;x:=c[(i+j)>>1];
14 repeat
15 while c[i]<x do inc(i);
16 while c[j]>x do dec(j);
17 if i<=j then
18 begin
19 y:=c[i];c[i]:=c[j];c[j]:=y;
20 y:=a[i];a[i]:=a[j];a[j]:=y;
21 y:=b[i];b[i]:=b[j];b[j]:=y;
22 inc(i);dec(j);
23 end;
24 until i>j;
25 if i<r then sort(i,r);
26 if j>l then sort(l,j);
27 end;
28 procedure init;
29 begin
30 readln(n,m);
31 ans:=maxlongint;
32 for i:=1 to n do begin readln(w[i]);ans:=min(ans,w[i]);end;
33 for i:=1 to m do begin readln(a[i],b[i],c[i]);inc(c[i],c[i]+w[a[i]]+w[b[i]]);end;
34 sort(1,m);
35 end;
36 procedure main;
37 begin
38 for i:=1 to n do fa[i]:=i;j:=1;
39 for i:=1 to n-1 do
40 begin
41 while find(a[j])=find(b[j]) do inc(j);
42 fa[find(a[j])]:=find(b[j]);
43 inc(ans,c[j]);
44 end;
45 writeln(ans);
46 end;
47 begin
48 assign(input,‘input.txt‘);assign(output,‘output.txt‘);
49 reset(input);rewrite(output);
50 init;
51 main;
52 close(input);close(output);
53 end.