题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=542
//C++代码
//ps:本题的Sample Output有误
#include<iostream>
#include<queue>
using namespace std;
struct Edge{
int u,v,w;
bool operator <(const Edge a) const{
return w>a.w;
}
}edge;
int n,s[1005];
priority_queue<Edge> pq;
void Union(int x,int y){
s[y]=x;
}
int Find(int x){
if(s[x]<0) return x;
return s[x]=Find(s[x]);
}
void Kruskal(){
int num=0,sum=0,i,x[1005],y[1005];
for(i=1;i<=n;i++) s[i]=-1;
while(!pq.empty() && num<n-1){
edge=pq.top();
pq.pop();
if(Find(edge.u)!=Find(edge.v)){
Union(Find(edge.u),Find(edge.v));
sum+=edge.w;
num++;
x[num]=edge.u;
y[num]=edge.v;
}
}
cout<<edge.w<<endl;
cout<<num<<endl;
for(i=1;i<=num;i++) cout<<x[i]<<" "<<y[i]<<endl;
while(!pq.empty()) pq.pop();
}
int main(){
int m,i;
while(cin>>n>>m){
for(i=1;i<=m;i++){
cin>>edge.u>>edge.v>>edge.w;
pq.push(edge);
}
Kruskal();
}
return 0;
}