Ice_cream’s world III

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 6   Accepted Submission(s) : 3
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 10 4 0
 
Sample Output
10 impossible
题解:
联通所有的路的最小代价;不连通就输出impossible
prime代码:
 #include<stdio.h>
#include<string.h>
const int INF=0x3f3f3f3f;
const int MAXN=;
int N,M,answer;
int map[MAXN][MAXN],low[MAXN],vis[MAXN];
void prime(){
int k,flot=,temp;
memset(vis,,sizeof(vis));
vis[]=;
for(int i=;i<N;i++)
low[i]=map[][i];
for(int i=;i<N;i++){
temp=INF;
for(int j=;j<N;j++)
if(!vis[j]&&temp>low[j])temp=low[k=j];
if(temp==INF){
if(flot==N)printf("%d\n",answer);
else puts("impossible");
break;
}
answer+=temp;
vis[k]=;
flot++;
for(int j=;j<N;j++)
if(!vis[j]&&low[j]>map[k][j])
low[j]=map[k][j];
}
}
int main(){
int a,b,c;
while(~scanf("%d%d",&N,&M)){answer=;
memset(map,INF,sizeof(map));
while(M--){
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])
map[a][b]=map[b][a]=c;
}
prime();
puts("");
}
return ;
}

Ice_cream’s world III(prime)的更多相关文章

  1. poj 2349 Arctic Network(prime)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25165   Accepted: 7751 Description The ...

  2. 素数(Prime)

    素数的判断: #include<math.h> bool IsPrime(int n) { ) return false; int sqr = (int)sqrt(1.0*n); ; i& ...

  3. [LeetCode]534. 游戏玩法分析 III(Mysql)

    题目 Table: Activity +--------------+---------+ | Column Name | Type | +--------------+---------+ | pl ...

  4. hdu 1028 Ignatius and the Princess III(母函数)

    题意: N=a[1]+a[2]+a[3]+...+a[m];  a[i]>0,1<=m<=N; 例如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + ...

  5. 【HDU2122】Ice_cream’s world III(MST基础题)

    2坑,3次WA. 1.判断重边取小.2.自边舍去. (个人因为vis数组忘记初始化,WA了3次,晕死!!) #include <iostream> #include <cstring ...

  6. hdu--1028--Ignatius and the Princess III (母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. LeetCode 5198. 丑数 III(Java)容斥原理和二分查找

    题目链接:5198. 丑数 III 请你帮忙设计一个程序,用来找出第 n 个丑数. 丑数是可以被 a 或 b 或 c 整除的 正整数. 示例 1: 输入:n = 3, a = 2, b = 3, c ...

  8. Java实现 LeetCode 437 路径总和 III(三)

    437. 路径总和 III 给定一个二叉树,它的每个结点都存放着一个整数值. 找出路径和等于给定数值的路径总数. 路径不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点 ...

  9. Java实现 LeetCode 337 打家劫舍 III(三)

    337. 打家劫舍 III 在上次打劫完一条街道之后和一圈房屋后,小偷又发现了一个新的可行窃的地区.这个地区只有一个入口,我们称之为"根". 除了"根"之外,每 ...

随机推荐

  1. hdu1172猜数字(暴力枚举)

    猜数字 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. IOS反地理编码取得城市名称

    // 获取当前所在的城市名 CLGeocoder *reverseGeocoder=[[CLGeocoder alloc] init]; [reverseGeocoder reverseGeocode ...

  3. 性能优化之Hibernate缓存讲解、应用和调优

    JavaMelody——一款性能监控.调优工具, 通过它让我觉得项目优化是看得见摸得着的,优化有了针对性.而无论是对于分布式,还是非分布,缓存是提示性能的有效工具. 数据层是EJB3.0实现的,而EJ ...

  4. js面向对象编程:if中能够使用那些作为推断条件呢?

       在全部编程语言中if是最长用的推断之中的一个.但在js中究竟哪些东西能够在if中式作为推断表达式呢? 比如怎样几行,仅仅是少了一个括号.真假就全然不同.究竟表示什么含义呢 var obj={}; ...

  5. C#主要字典集合性能对比[转]

    A post I made a couple days ago about the side-effect of concurrency (the concurrent collections in ...

  6. 一个SQL 建表格式

    CREATE TABLE [dbo].[SysSample]([Id] [varchar](50) NOT NULL,[Name] [varchar](50) NULL,[Age] [int] NUL ...

  7. Spring 入门 AOP

    通过一个小例子演视怎么使用 Spring 现实面向切面编程. 导入 Spring 所需要的包 spring-framework-2.5.6 版需要导入以下包: 1.----- spring.jar 2 ...

  8. python 学习之爬虫练习

    通过学习python,写两个简单的爬虫,没用线程,本地抓取速度还不错,有些瑕疵就是抓的图片有些显示不出来,代码做个笔记记录下: # -*- coding:utf-8 -*- import re imp ...

  9. 自动化单元测试工具 EvoSuite 的简单使用

    一.EvoSuite简介 EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行. 通过使用此自动测 ...

  10. 获取电脑cpu的使用情况

    using System; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static void ...