zoukankan      html  css  js  c++  java
  • [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-1,e[i].w);
        return 0;
    }
    
  • 相关阅读:
    Git 操作
    SVN
    一维数组
    常见的数学方法
    常用事件
    function函数
    while;do while; for循环
    JS中的变量提升
    关于js的单双引号嵌套问题
    db.collection is not a function
  • 原文地址:https://www.cnblogs.com/Vanisher/p/9135988.html
Copyright © 2011-2022 走看看