1 #include<cstdio>
2
3 #include<cstdlib>
4
5 #include<cmath>
6
7 #include<cstring>
8
9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 1000000000
24
25 #define maxn 1000000+1000
26
27 #define maxm 2000000+10000
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define pa pair<int,int>
34
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42
43 #define mod 1000000007
44
45 using namespace std;
46
47 inline int read()
48
49 {
50
51 int x=0,f=1;char ch=getchar();
52
53 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
54
55 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
56
57 return x*f;
58
59 }
60 ll h[maxn];
61 int n,m,cnt,sum,tot,head[maxn],fa[maxn],a[maxm],b[maxm],w[maxm],q[maxn];
62 bool can[maxn];
63 struct edge{int go,next;}e[2*maxm];
64 struct rec{int x,y;ll w;}c[maxm];
65 inline bool cmp(rec a,rec b)
66 {
67 return h[a.y]>h[b.y]||(h[a.y]==h[b.y]&&a.w<b.w);
68 }
69 inline void insert(int x,int y)
70 {
71 e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
72 }
73 inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
74 int main()
75
76 {
77 freopen("input.txt","r",stdin);
78 freopen("output.txt","w",stdout);
79 n=read();m=read();
80 for1(i,n)h[i]=read();
81 for1(i,m)
82 {
83 int x=read(),y=read();
84 if(h[x]>=h[y])insert(x,y);
85 if(h[y]>=h[x])insert(y,x);
86 a[i]=x;b[i]=y;w[i]=read();
87 }
88 cnt=0;can[1]=1;
89 int l,r;
90 for(l=0,r=1,q[1]=1;l<=r;l++)
91 for(int i=head[q[l]],y;i;i=e[i].next)
92 if(!can[y=e[i].go])q[++r]=y,can[y]=1;
93 printf("%d ",r);
94 sum=0;
95 for1(i,m)if(can[a[i]]&&can[b[i]])
96 {
97 if(h[a[i]]>=h[b[i]])c[++sum].x=a[i],c[sum].y=b[i],c[sum].w=w[i];
98 if(h[b[i]]>=h[a[i]])c[++sum].x=b[i],c[sum].y=a[i],c[sum].w=w[i];
99 }
100 sort(c+1,c+sum+1,cmp);
101 for1(i,n)fa[i]=i;
102 int j=1;
103 //for1(i,sum)cout<<c[i].x<<‘ ‘<<c[i].y<<‘ ‘<<c[i].w<<endl;
104 ll ans=0;
105 for1(i,r-1)
106 {
107 while(find(c[j].x)==find(c[j].y))j++;
108 fa[find(c[j].x)]=find(c[j].y);
109 ans+=c[j].w;
110 j++;
111 }
112 printf("%lld\n",ans);
113
114 return 0;
115
116 }