靠, 没仔细看题, 第二个竟然是最小生成树的边数, 白白wa了2次, kruskal的模板题, 测试样例错的, 大家别理会。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int Maxm = 15010;
const int Maxn = 1010;
const int inf = 0x3f3f3f;
typedef struct {
int a, b, w;
bool flag;
} node;
node edge[Maxm];
int n, m, ans, fa[Maxn], path;
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a>b?b:a;
}
bool cmp1(node a,node b)
{
return a.w < b.w;
}
bool cmp2(node a,node b)
{
if(a.a == b.a)
return a.b < b.b;
return a.a < b.a;
}
void ini()
{
for(int i = 1; i <= n; ++ i)
{
fa[i] = i;
}
}
int fint(int a)
{
if(fa[a] != a)
fa[a] = fint(fa[a]);
return fa[a];
}
void kruskal()
{
int cou = 1;
path = inf;
for(int i=0; i<m; ++i)
{
int t1 = fint(edge[i].a);
int t2 = fint(edge[i].b);
if(t1 != t2)
{
fa[t1] = t2;
++cou;
path = min(edge[i].w, path);
ans = max(ans, edge[i].w);
edge[i].flag = true;
}
if(cou == n)
return;
}
}
int main(void)
{
scanf("%d%d",&n,&m);
for(int i = 0; i < m; ++ i)
{
scanf("%d%d%d",&edge[i].a, &edge[i].b, &edge[i].w);
edge[i].flag = false;
}
sort(edge, edge+m, cmp1);
ans = 0;
ini();
kruskal();
printf("%d\n%d\n",ans,n-1);
sort(edge, edge+m, cmp2);
for(int i=0; i<m; ++i)
if(edge[i].flag)
printf("%d %d\n",edge[i].a,edge[i].b);
return 0;
}