[bzoj1083][SCOI2005]繁忙的都市【MST】

【题目链接】
  http://www.lydsy.com/JudgeOnline/problem.php?id=1083
【题解】
  MST裸题。。。

/* --------------
    user Vanisher
    problem bzoj-1083
----------------*/
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
# define    M       10010
# define    N       310
using namespace std;
int read(){
    int tmp=0, fh=1; char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') fh=-1; ch=getchar();}
    while (ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0'; ch=getchar();}
    return tmp*fh;
}
struct node{
    int u,v,w;
}e[M];
int f[N],n,m;
bool cmp(node x, node y){
    return x.w<y.w;
}
int dad(int x){
    if (f[x]==x) return x;
        return f[x]=dad(f[x]);
}
int main(){
    n=read(), m=read();
    for (int i=1; i<=n; i++) f[i]=i;
    for (int i=1; i<=m; i++)
        e[i].u=read(), e[i].v=read(), e[i].w=read();
    sort(e+1,e+m+1,cmp);
    int num=n,i=0;
    while (num>1){
        i++;
        int u=dad(e[i].u), v=dad(e[i].v);
        if (u!=v) f[u]=v, num--;
    } 
    printf("%d %d\n",n-1,e[i].w);
    return 0;
}
posted @ 2018-03-06 19:25  Vanisher  阅读(44)  评论(0编辑  收藏