#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define ll long long #define INF 0x7fffffff #define re register
voidkruskal() { for(re int i = 1; i <= n; i++) fa[i] = i; sort(e + 1, e + t + 1, mysort); for(re int i = 1; i <= t; i++) { if(find(e[i].x) != find(e[i].y)) { ans = ans + e[i].k; fa[find(e[i].x)] = find(e[i].y); } } }
intmain() { n = read(); m = read(); for(re int i = 1; i <= n; i++) h[i] = read(); for(re int i = 1; i <= m; i++) { u = read(); v = read(); k = read(); if(h[u] >= h[v]) add(u,v,k); if(h[u] <= h[v]) add(v,u,k); } dfs(1); for(re int i = 1; i <= cnt; i ++) { if((edge[i].from != edge[i - 1].to || edge[i].to != edge[i - 1].from) && vis[edge[i].from] && vis[edge[i].to]) { e[++t].k = edge[i].k; e[t].x = edge[i].from; e[t].y = edge[i].to; } } kruskal(); for(re int i = 1; i <= n; i++) if(vis[i]) tot ++; printf("%lld %lld\n", tot, ans); return0; }