题目本来很简单但也很神奇,样例竟然是错的,,
其实就是求一个最小的生成树,然后输出其中的最大边,边的个数,和所有的边
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#define size_num 1200
#define num_edge 15100
#include<vector>
using namespace std;
int p[size_num],r[num_edge];
vector<int> que;
int m,n,v[num_edge],u[num_edge],w[num_edge];
int cmp(const int i,const int j){return w[i]<w[j];}
int findp(int x){return p[x]==x?x:p[x]=findp(p[x]);}
void read()
{
for(int i=1;i<=m;i++)
cin>>u[i]>>v[i]>>w[i];
}
void deal()
{
int counter=0,e;
for(int i=1;i<=n;i++) p[i]=i;//初始化并查集
for(int i=1;i<=m;i++) r[i]=i;//初始化边的序号
sort(r+1,r+m+1,cmp);
for(int i=1;i<=m&&counter<n-1;i++)
{
e=r[i];
int x=findp(u[e]),y=findp(v[e]);
if(x!=y)
{
counter++;
p[x]=y;
que.push_back(e);
}
}
cout<<w[e]<<endl<<n-1<<endl;
for(vector<int>::iterator it=que.begin();it!=que.end();++it)
cout<<u[*it]<<" "<<v[*it]<<endl;
que.clear();
}
int main()
{
while(cin>>n>>m)
{
read();
deal();
}
return 0;
}