zoukankan      html  css  js  c++  java
  • bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083

    思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权值就好了

    实现代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    const int M = 3e4+10;
    int f[M],cnt;
    
    struct node{
        int u,v,w;
    }e[100010];
    
    bool cmp(node a,node b){
        return a.w < b.w;
    }
    
    int Find(int x){
        if(x == f[x]) return x;
        return f[x] = Find(f[x]);
    }
    
    int main()
    {
        int ans=0 ,n, m;
        cin>>n>>m;
        for(int i = 1;i <= m;i ++){
            cin>>e[i].u>>e[i].v>>e[i].w;
        }
        sort(e+1,e+1+m,cmp);
        for(int i = 1;i <= n;i ++) f[i] = i;
        for(int i = 1;i <= m;i ++){
            int fx = Find(e[i].u),fy = Find(e[i].v);
            if(fx != fy){
                f[fy] = fx;
                ans = e[i].w;
            }
        }
        cout<<n-1<<" "<<ans<<endl;
    }
  • 相关阅读:
    mysql 导入excel 或 .csv
    导出Excel
    jQuery.ajax
    在web项目中配置log4j
    数据分析入门
    jdbc的配置(更新中)
    Maven中项目的启动
    Maven中的配置文件
    Maven的插件管理
    Maven的依赖管理
  • 原文地址:https://www.cnblogs.com/kls123/p/10573954.html
Copyright © 2011-2022 走看看