1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<vector>
5 #include<queue>
6 #include<algorithm>
7 #define ll long long
8 #define INF 0x3f3f3f3f
9 #define maxn 2100000
10 using namespace std;//注意long long
11
12 int p[maxn],fa[maxn],vis[maxn],num,n,m,cnt;
13 ll ans,h[maxn];
14
15 struct node{
16 int u,v,next;ll val;
17 }edge[maxn];
18 bool cmp(node a,node b){
19 return h[a.u]>h[b.u]||(h[a.u]==h[b.u])&&(a.val<b.val);
20 }
21
22
23 //BingChaji
24 int Find(int a){
25 return a==fa[a]?a:fa[a]=Find(fa[a]);
26 }
27 int unite(int a,int b){
28 int pa=Find(a),pb=Find(b);
29 if(pa!=pb) fa[pa]=pb;
30 }
31
32 void add(int x,int y,ll z){
33 edge[++num].v=x;
34 edge[num].u=y;
35 edge[num].val=z;
36 edge[num].next=p[x];
37 p[x]=num;
38 }
39
40 void bfs(){
41 vis[1]=1;
42 queue<int> q;
43 q.push(1);
44
45 while(!q.empty()){
46 int v=q.front();q.pop();
47 cnt++;
48
49 for(int e=p[v];e;e=edge[e].next){
50 if(!vis[edge[e].u]){
51 vis[edge[e].u]=1;
52 q.push(edge[e].u);
53 }
54 }
55 }
56 }
57
58 void kru(){
59 sort(edge+1,edge+num+1,cmp);
60 for(int i=1;i<=num;i++){
61 if(!vis[edge[i].u]||!vis[edge[i].v])continue;
62 if(Find(edge[i].u)==Find(edge[i].v))continue;
63 unite(edge[i].u,edge[i].v);
64 ans+=edge[i].val;
65 }
66 }
67
68 int main(){
69 // freopen("01.in","r",stdin);
70 scanf("%d%d",&n,&m);//注意long long
71 for(int i=1;i<=n;i++) fa[i]=i;
72 for(int i=1;i<=n;i++) scanf("%d",&h[i]);
73 for(int i=1;i<=m;i++){
74 int u,v;ll w;
75 scanf("%d%d%lld",&u,&v,&w);
76 if(h[u]>=h[v])add(u,v,w);
77 if(h[u]<=h[v])add(v,u,w);
78 }
79
80
81 bfs();
82 kru();
83
84 printf("%d %lld\n",cnt,ans);
85 return 0;
86 }