Ice_cream’s world III

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

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
 
思路:prime,考虑重边!!!
AC代码:
 #include<stdio.h>
#include<string.h>
int map[][],dist[];
int vis[],n;
void init1()
{
int i,j;
for(i = ;i < n;i ++)
{
for(j = ;j < n;j ++)
{
if(i != j)
map[i][j] = << ;
}
}
}
void init2()
{
int i;
memset(vis,,sizeof(vis));
for(i = ;i < n;i ++)
dist[i] = map[][i];
}
int main()
{
int m,i,j,k,cnt;
int min,len,sum,a,b;
while(~scanf("%d%d",&n,&m))
{
init1();
sum = cnt = ;
while(m--)
{
scanf("%d%d%d",&a,&b,&len);
if(len < map[a][b])
map[a][b] = map[b][a] = len;
}
init2();
vis[] = ;
for(i = ;i < n;i ++)
{
min = << ;
for(j = ;j < n;j ++)
{
if(!vis[j] && min > dist[j])
{
min = dist[j];
k = j;
}
}
vis[k] = ;
if(min != << )
{
cnt++;
sum += min;
}
for(j = ;j < n;j ++)
{
if(!vis[j] && dist[j] > map[k][j])
dist[j] = map[k][j];
}
}
if(cnt == n-)
printf("%d\n\n",sum);
else
printf("impossible\n\n");
}
return ;
}

Ice_cream’s world III--2122的更多相关文章

  1. hdoj 2122 Ice_cream’s world III

    并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  2. HDU 2122 Ice_cream’s world III【最小生成树】

    解题思路:基础的最小生成树反思:不明白为什么i从1开始取,就一直WA,难道是因为村庄的编号是从0开始的吗 Ice_cream’s world III Time Limit: 3000/1000 MS ...

  3. hdoj 2122 Ice_cream’s world III【最小生成树】

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

  4. Ice_cream’s world III(prime)

    Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  5. Ice_cream’s world III

    Ice_cream's world III Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  6. A - Ice_cream’s world III

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

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

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

  8. hdoj--2122--Ice_cream’s world III(克鲁斯卡尔)

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

  9. 【转】并查集&MST题集

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

随机推荐

  1. java新手笔记22 接口示例2

    1.USB package com.yfs.javase; public interface USB { //定义规范 public void read(); public void write(); ...

  2. CSS当中color的四种表示方法

    这是我的第一篇博客,所以写的东西会比较简单. css当中,好多地方都会用到color属性,用来使html内容丰富多彩,例如:background-color:border-color: 第一种表示法使 ...

  3. checkbox 选择一个checkbox,其他checkbox也会选择

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  4. 现代密码学应用的范例-PGP

    PGP(Pretty Good Privacy),是一个基于RSA公钥加密体系的邮件加密软件. 产生背景: 电子邮件在传输中使用SMTP协议存在这样的问题 1.无法保证邮件在传输过程中不被人偷看 2. ...

  5. 【实习记】2014-08-29算法学习Boyer-Moore和最长公共子串(LCS)

        昨天的问题方案一:寻找hash函数,可行性极低.方案二:载入内存,维护成一个守护进程的服务.难度比较大.方案三:使用前5位来索引,由前3位增至前5位唯一性,理论上是分拆记录扩大100倍,但可以 ...

  6. Mysql锁机制和事务控制

    如何加锁 锁定表的语法:    LOCK TABLES    tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}    [, tbl_n ...

  7. php中文编码

    header("Content-type: text/html; charset=utf-8"); header('Location: http://www.example.com ...

  8. citrix xen server 虚拟机无法关闭的问题

    悲剧的一台windows的虚拟机无法重启无法关机.如下图,一直卡住不动. 首先找到这台机器: [root@xenserver- xen]# xe vm-list name-label=-vss\ se ...

  9. javascript之事件

    客户端javascript程序采用了异步事件驱动编程模型. 相关事件的几个概念: 事件类型(event type):用来说明发生什么类型事件的字符串: 事件目标(event target):发生事件的 ...

  10. MySQL简单使用

    1.启动MySQL服务器实际上上篇已讲到如何启动MySQL.两种方法:一是用winmysqladmin,如果机器启动时已自动运行,则可直接进入下一步操作.二是在DOS方式下运行 d:/mysql/bi ...