1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 #define maxn 1000020
7
8 typedef long long ll;
9
10 int h[maxn];
11
12 struct node{
13 int u,v,w;
14 bool operator < (node a)const{
15 if ( min(h[u],h[v]) == min(h[a.u],h[a.v]) ) return w < a.w;
16 return min(h[u],h[v]) > min(h[a.u],h[a.v]);
17 }
18 }dt[maxn];
19 struct node2{
20 int next,to;
21 }e[maxn * 2];
22 int head[maxn],cnt;
23 ll ans;
24 int num,vis[maxn],n,m,q[maxn],hh,tt;
25 int fa[maxn];
26
27 inline void adde(int x,int y){
28 e[++cnt].to = y;
29 e[cnt].next = head[x];
30 head[x] = cnt;
31 }
32 void bfs(){
33 q[tt++] = 1 , vis[1] = 1;
34 while ( hh < tt ){
35 int x = q[hh++];
36 for (int i = head[x] ; i ; i = e[i].next){
37 if ( !vis[e[i].to] ){
38 vis[e[i].to] = 1,q[tt++] = e[i].to;
39 }
40 }
41 }
42 }
43 int getfa(int x){
44 if ( x == fa[x] ) return x;
45 return fa[x] = getfa(fa[x]);
46 }
47 void solve(){
48 for (int i = 1 ; i <= n ; i++) if ( vis[i] ) num++;
49 sort(dt + 1,dt + m + 1);
50 for (int i = 1 ; i <= n ; i++) fa[i] = i;
51 for (int i = 1 ; i <= m ; i++){
52 if ( !vis[dt[i].u] || !vis[dt[i].v] ) continue;
53 int p = getfa(dt[i].u) , q = getfa(dt[i].v);
54 if ( p != q ){
55 fa[p] = q;
56 ans += (ll)dt[i].w;
57 }
58 }
59 printf("%d %lld\n",num,ans);
60 }
61 int main(){
62 scanf("%d %d",&n,&m);
63 for (int i = 1 ; i <= n ; i++) scanf("%d",&h[i]);
64 for (int i = 1 ; i <= m ; i++){
65 int x,y,w;
66 scanf("%d %d %d",&x,&y,&w);
67 if ( h[x] >= h[y] ) adde(x,y);
68 if ( h[y] >= h[x] ) adde(y,x);
69 dt[i] = (node){x,y,w};
70 }
71 bfs();
72 solve();
73 return 0;
74 }