https://www.luogu.org/problemnew/show/P2330
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN=5005,MAXM=400005;
int n,m,fa[MAXN],cnt,num,s,ma;
struct cyq{
int u,v,w;
}a[MAXM];
int get(){
char cc=getchar();
int res=0;
while (cc<'0'||cc>'9') cc=getchar();
while (cc>='0'&&cc<='9'){
res=(res<<3)+(res<<1)+cc-'0';
cc=getchar();
}
return res;
}
bool cmp(cyq aa,cyq bb){
return aa.w<bb.w;
}
int find(int x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
int main(){
int x,y,w;n=get();m=get();
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=m;i++){
x=get();y=get();w=get();
a[++cnt].u=x;a[cnt].v=y;a[cnt].w=w;
}
sort(a+1,a+1+cnt,cmp);num=1;
for(int i=1;i<n;i++){
while(find(a[num].u)==find(a[num].v) && num<=m) ++num;
fa[find(a[num].u)]=a[num].v;++s;ma=a[num].w;
}
printf("%d %d\n",s,ma);
return 0;
}