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. 格而知之6:我所理解的Runtime(1)

    基本简介 1.根据官方文档,OC有一个特性:它会尽可能把一些决定从编译时和链接时推迟到运行时才处理,所以这门语言需要的就不只是一个编译器,它还需要一个runtime系统来处理那些已经被编译过的代码. ...

  2. Android学习总结——SharedPreferences

    SharePreferences存储方式,只是轻量级数据存储,xml格式的数据显示方式.简单存储步骤如下:一:获取SharePreferences对象1.SharedPreferences pref ...

  3. 擦肩而过的那块牌--记ACM_ICPC西安赛区现场赛

    说了那么多次orz,这次是真的orz了.去了西安打区域赛,也想过会打铁.但当终于那一刻确定打铁了之后.心里还是非常不开心的,颁奖的时候思考熊那家伙嚣张的举起来手中那个金杯,说实话闪到我眼了(太亮了QA ...

  4. 新博客 Fighting

    C3  Viso绘图 的 几种关系

  5. J - A + B Problem II(第二季水)

    Description I have a very simple problem for you. Given two integers A and B, your job is to calcula ...

  6. [转载]vs2010中臃肿的ipch和sdf文件

    使用VS2010建立C++解决方案时,会生成SolutionName.sdf和一个叫做ipch的文件夹,这两个文件再加上*.pch等文件使得工程变得非常的庞大,一个简单的程序都会占用几十M的硬盘容量, ...

  7. js 控制不能输入空格

    onkeydown="if(event.keyCode==32) return false"

  8. c#接口定义与应用

    public interface IBankAccount //只能加public修饰符,或者什么都不加 { void Playin(decimal money); //函数前不加任何修饰符号 boo ...

  9. Font Awesome 4.0.3 字体图标完美兼容IE7

    1.下载Font Awesome 4.0.3兼容包,http://www.thinkcmf.com/index.php?m=font 2.解压,并放到自己网站系统合适的位置(如果你的站已使用Font ...

  10. LFS,编译自己的Linux系统 - 前言

    近期工作计划:1. 上班时,用Django编写一个网站:2. 下班时,用C#.WPF编写一个单机版应用软件:3. 其他时间,根据LFS编译自己的Linux系统. LFS是一本书,书中列出了从零开始编译 ...