Ice_cream’s world III--2122
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
#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的更多相关文章
- hdoj 2122 Ice_cream’s world III
并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDU 2122 Ice_cream’s world III【最小生成树】
解题思路:基础的最小生成树反思:不明白为什么i从1开始取,就一直WA,难道是因为村庄的编号是从0开始的吗 Ice_cream’s world III Time Limit: 3000/1000 MS ...
- 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 ...
- Ice_cream’s world III(prime)
Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- Ice_cream’s world III
Ice_cream's world III Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- A - Ice_cream’s world III
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- 【HDU2122】Ice_cream’s world III(MST基础题)
2坑,3次WA. 1.判断重边取小.2.自边舍去. (个人因为vis数组忘记初始化,WA了3次,晕死!!) #include <iostream> #include <cstring ...
- 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 ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
随机推荐
- js hashMap
/** * MAP对象,实现MAP功能 * * 接口: * size() 获取MAP元素个数 * isEmpty() 判断MAP是否为空 * clear() 删除MAP所有元素 * put(key, ...
- 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 ...
- 【BZOJ3270】【高斯消元】博物馆
Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的样式.它包含由m条走廊连接的n间房间,并且满足可以从任何一 ...
- mysql SELECT INTO OUTFILE ,can't create file (转)
原文 http://blog.sina.com.cn/s/blog_6a5e34ad0100zfbi.html (转) 命令行模式进入mysql #mysql -uroot -p12345 #sel ...
- (转载)StringGrid常用属性和常用操作
Delphi StringGrid常用属性和常用操作 StringGrid组件用于建立显示字符串的网格,与电子表格相似.它可使表格中的字符串和相关对象操作简单化.StringGrid组件提供了许多可控 ...
- LeetCode【第一题】Two Sum
准备刷一刷LeetCode了. 题目: ''' Given an array of integers, return indices of the two numbers such that they ...
- Swift lazy 修饰符和方法
LAZY 修饰符和 LAZY 方法 由 王巍 (@ONEVCAT) 发布于 2015/10/07 延时加载或者说延时初始化是很常用的优化方法,在构建和生成新的对象的时候,内存分配会在运行时耗费不少时间 ...
- 【转】mybatis在xml文件中处理大于号小于号的方法
http://blog.csdn.net/zheng0518/article/details/10449549 第一种方法: 用了转义字符把>和<替换掉,然后就没有问题了. SELECT ...
- JavaFX 开发是遇到一些问题记录
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "PingFang SC"; color: #000000; min-he ...
- 转:浅谈命令查询职责分离(CQRS)模式
原文来自于:http://www.cnblogs.com/yangecnu/p/Introduction-CQRS.html 在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查 ...