Ice_cream’s world III

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1250    Accepted Submission(s): 413

Problem Description
ice_cream’s world becomes stronger and stronger; every road is built as undirected. The queen enjoys traveling around her world; the queen’s requirement is like II problem, beautifies the roads, by which there are some ways from every city to the capital. The project’s cost should be as less as better.
Input
Every case have two integers N and M (N<=1000, M<=10000) meaning N cities and M roads, the cities numbered 0…N-1, following N lines, each line contain three integers S, T and C, meaning S connected with T have a road will cost C.
Output
If Wiskey can’t satisfy the queen’s requirement, you must be output “impossible”, otherwise, print the minimum cost in this project. After every case print one blank.
Sample Input
2 1 0 1 104 0
Sample Output
10impossible
Author
Wiskey
Source
HDU 2007-10 Programming Contest_WarmUp
Recommend
威士忌   |   We have carefully selected several similar problems for you:  2121 2119 2129 2118 2117 

Statistic | Submit | Discuss | Note

最小生成树 kruskal算法

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{int a,b,cost;
}c[10005];
int fa[1005];
void init(int n)
{for(int i=0;i<n;i++)fa[i]=i;
}
bool cmp(node x,node y)
{return x.cost<y.cost;
}
int find(int x)
{if(fa[x]!=x) fa[x]=find(fa[x]);return fa[x];
}
int main()
{int n,k;while(~scanf("%d %d",&n,&k)){init(n);for(int i=0;i<k;i++)scanf("%d %d %d",&c[i].a,&c[i].b,&c[i].cost);sort(c,c+k,cmp);int sum=0;for(int i=0;i<k;i++){int x=find(c[i].a);int y=find(c[i].b);if(x!=y)sum+=c[i].cost,fa[x]=y;}int count=0;for(int i=0;i<n;i++)if(fa[i]==i)count++;if(count!=1)printf("impossible\n\n");elseprintf("%d\n\n",sum);}return 0;
}

hdu2122 Ice_cream’s world III(MST)相关推荐

  1. HDU - 2122 Ice_cream’s world III

    ice_cream's world becomes stronger and stronger; every road is built as undirected. The queen enjoys ...

  2. 【转】并查集MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 ...

  3. 杭电2122Ice_cream’s world III

    Ice_cream's world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  5. android资源文件下的图片绝对路径,如何获取drawable目录下的图片绝对路径

    Public DNS (公共域名解析服务) 114DNS 服务IP:114.114.114.114, 114.114.115.115 拦截 钓鱼病毒木马网站:114.114.114.119, 114. ...

  6. UA MATH571B 试验设计III 单因素试验设计1

    UA MATH571B 试验设计III 单因素试验设计 单因素ANOVA 模型设定与假设 ANOVA F检验 单因素ANOVA 方差分析(Analysis of Variance,ANOVA)是两样本 ...

  7. UA MATH571A 一元线性回归III 方差分析与相关性分析

    UA MATH571A 一元线性回归III 方差分析与相关性分析 ANOVA Table F检验 回归系数的F检验 F检验与t检验等价 广义线性检验方法 R2R^2R2 数值例子:女性肌肉量与年龄的关 ...

  8. 图论复习——最小生成树MST

    知识点 MST的构造 Boruvka算法常用于解决这类问题:给你n个点,每个点有点权,任意两个点之间有边权,边权为两个点权用过某种计算方式得出,求最小生成树.动图 MST上的确定性和存在性问题 最小生 ...

  9. Parametric MST(贪心)

    Parametric MST [Link](Problem - F - Codeforces) 题意 ​ 给你一个nnn个结点的完全图,第iii个点的权重为aia_iai​,对于任意两个点的边权wi, ...

  10. 剑指offer:面试题32 - III. 从上到下打印二叉树 III

    题目: 从上到下打印二叉树 III 请实现一个函数按照之字形顺序打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右到左的顺序打印,第三行再按照从左到右的顺序打印,其他行以此类推. 例如: 给定 ...

最新文章

  1. 头条Android面试题,史上最全的Android面试题集锦(五)
  2. 手脱ASProtect v1.23 RC1(无Stolen Code)
  3. 深入理解ElasticSearch(七):执行分布式检索
  4. 计算机组成原理中英对照篇,信息科学系课程介绍(中英对照).doc
  5. 【Python爬虫】微信公众号历史文章和文章评论API分析
  6. 【HUAWEI Mate30】抽奖啦!华为IoT新福利上线!
  7. cmd 日志刷新卡屏
  8. 【Python-3.5】绘制世界人口地图
  9. 删除MSSQL数据库text字段中恶意脚本Script=***.js/script的方法
  10. 大专生三面蚂蚁金服,王道训练营java百度云盘
  11. array函数python_python中如何使用numpy.array函数创建数组?
  12. OSI第三层:网络层功能及作用OSI第三层:网络层功能及作用
  13. 【华为OD机试 2023】完美走位(C++ Java JavaScript Python 100%)
  14. 苹果企业号-通过网页下载应用,部署应用分发服务器
  15. 你了解石墨烯的特性、应用?都有什么?
  16. java -Xms -Xmx -XX:PermSize -XX:MaxPermSize
  17. ESP8266学习之路一——WiFi STA
  18. public static void main(String[] args)
  19. 收藏:猪蹄的十种吃法
  20. 学生信息管理系统设计 java_Java程序设计——学生基本信息管理系统(团队+个人)...

热门文章

  1. [乐意黎原创]云南省红河州泸西县各乡镇及村委会区划代码和城乡划分代码
  2. token是什么?(加密)
  3. Python零基础爬虫速成②:批量爬取微信公众号图片(基于beautifulsoup爬取吉他谱)
  4. Modelica资料整理
  5. C#实现最简单的文本加密方法
  6. 基于Renascence架构的SQL查询引擎设计
  7. 程序员眼中的中国传统文化_王阳明《传习录》2
  8. Minimax Problem
  9. laravel 框架使用hdjs 实现多图上传功能
  10. 64qam带宽计算_信道带宽计算参考