0pts,纯手写,而且4TLE和1WA……
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+9;
ll n,m,a[N],rm,rrm,vis[N],fa[N],head[N];
struct edge{ll st,ed,w;}e[N];
struct node{ll nxt,ed,w,from;}ne[N];
inline ll read()
{
register ll x = 0,f = 1;
register char ch;
ch = getchar();
while(ch > '9' || ch < '0'){if(ch == '-') f = -f;ch = getchar();}
while(ch <= '9' && ch >= '0'){x = x * 10 + ch - 48;ch = getchar();}
return x * f;
}
inline bool cmp(edge x,edge y)
{
return (a[x.ed]==a[y.ed]?x.w<y.w:a[x.ed]>a[y.ed]);
}
inline void add(ll x,ll y,ll z)
{
ne[++rrm].nxt=head[x];
ne[rrm].from=x;
ne[rrm].ed=y;
ne[rrm].w=z;
head[x]=rrm;
}
inline void dfs(ll x)
{
vis[x]=1;
for(int i=head[x];i;i=ne[i].nxt)
if(vis[ne[i].ed]==0)
dfs(ne[i].ed);
}
inline ll Find(ll x)
{
return (fa[x]==x?x:fa[x]=Find(fa[x]));
}
int main()
{
n=read();rm=read();
for(int i=1;i<=n;i++)
a[i]=read();
for(int i=1;i<=rm;i++)
{
ll u,v,w;
u=read();v=read();w=read();
if(a[u]>=a[v])
add(u,v,w);
if(a[v]>=a[u])
add(v,u,w);
}
dfs(1);
for(int i=1;i<=rrm;i++)
if(vis[ne[i].from] && vis[ne[i].ed] && (ne[i].from!=ne[i-1].ed || ne[i].ed!=ne[i-1].from))
{
e[++m].st=ne[i].from;
e[m].ed=ne[i].ed;
e[m].w=ne[i].w;
}
ll vis_num=0,ans=0;
for(int i=1;i<=n;i++)
if(vis[i])
vis_num++;
printf("%lld ",vis_num);
sort(e+1,e+m+1,cmp);
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=m;i++)
if(Find(e[i].st)!=Find(e[i].ed))
ans=ans+e[i].w,fa[Find(e[i].st)]=Find(e[i].ed);
printf("%lld",ans);
return 0;
}