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. js hashMap

    /** * MAP对象,实现MAP功能 * * 接口: * size() 获取MAP元素个数 * isEmpty() 判断MAP是否为空 * clear() 删除MAP所有元素 * put(key, ...

  2. struts1、 struts2所有版本jar包下载地址大全

     jakarta-struts-1.2.2.tar.gz      30-Aug-2004 18:21   12M  jakarta-struts-1.2.2.tar.gz.asc  30-Aug-2 ...

  3. 【BZOJ3270】【高斯消元】博物馆

    Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的样式.它包含由m条走廊连接的n间房间,并且满足可以从任何一 ...

  4. mysql SELECT INTO OUTFILE ,can't create file (转)

    原文  http://blog.sina.com.cn/s/blog_6a5e34ad0100zfbi.html (转) 命令行模式进入mysql #mysql -uroot -p12345 #sel ...

  5. (转载)StringGrid常用属性和常用操作

    Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...

  6. LeetCode【第一题】Two Sum

    准备刷一刷LeetCode了. 题目: ''' Given an array of integers, return indices of the two numbers such that they ...

  7. Swift lazy 修饰符和方法

    LAZY 修饰符和 LAZY 方法 由 王巍 (@ONEVCAT) 发布于 2015/10/07 延时加载或者说延时初始化是很常用的优化方法,在构建和生成新的对象的时候,内存分配会在运行时耗费不少时间 ...

  8. 【转】mybatis在xml文件中处理大于号小于号的方法

    http://blog.csdn.net/zheng0518/article/details/10449549 第一种方法: 用了转义字符把>和<替换掉,然后就没有问题了. SELECT ...

  9. JavaFX 开发是遇到一些问题记录

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC"; color: #000000; min-he ...

  10. 转:浅谈命令查询职责分离(CQRS)模式

    原文来自于:http://www.cnblogs.com/yangecnu/p/Introduction-CQRS.html 在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查 ...