# BZOJ 1083: [SCOI2005]繁忙的都市

4 5
1 2 3
1 4 5
2 4 7
2 3 6
3 4 8

## Sample Output

3 6

——我是愉快的分割线——

#include<cstdio>
#include<algorithm>
using namespace std;

const int Maxn=300;
int Father[Maxn+10];
inline void initFather(){
for(int i=0;i<=Maxn;i++)Father[i]=i;
}
int getFather(int x){
return Father[x]=Father[x]==x?x:getFather(Father[x]);
}
inline void mergeFather(int x,int y){
int Fx=getFather(x),Fy=getFather(y);
if (Fx<Fy){
Father[Fy]=Fx;
}else{
Father[Fx]=Fy;
}
}
struct Edge_Node{
int x;
int y;
int cost;
};

const int Maxm=11000;
Edge_Node Edge[Maxm+10];
int n,m;
inline bool cmp(Edge_Node a,Edge_Node b){
if (a.cost<b.cost) return true;
return false;
}

int Ans=0;

int main(){
initFather();

scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)scanf("%d%d%d",&Edge[i].x,&Edge[i].y,&Edge[i].cost);
sort(Edge+1,Edge+m+1,cmp);

for (int i=1;i<=m;i++)
if (getFather(Edge[i].x)!=getFather(Edge[i].y)){
mergeFather(Edge[i].x,Edge[i].y);
Ans=Edge[i].cost;
}

printf("%d %d\n",n-1,Ans);
return 0;
} 

posted @ 2014-08-29 23:10  WNJXYK  阅读(74)  评论(0编辑  收藏