Ice_cream’s world III

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 10   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
 
Author
Wiskey
 
Source
HDU 2007-10 Programming Contest_WarmUp


#include<stdio.h>
#include<string.h>
#define INF 0xfffffff
int map[1010][1010],v[10001];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j,min,flag=0,sum=0;
memset(v,0,sizeof(v));
for(i=0;i<=1001;i++)
{
for(j=0;j<=1001;j++)
map[i][j]=INF;
}
while(m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])
map[a][b]=map[b][a]=c;
}
v[0]=1;
for(i=1;i<n;i++)
{
min=INF;
flag=0;
for(j=0;j<n;j++)
{
if(!v[j]&&map[0][j]<min)
{
min=map[0][j];
flag=j;
}
}
if(!flag)
break;
sum+=map[0][flag];
v[flag]=1;
for(j=0;j<n;j++)
{
if(!v[j]&&map[0][j]>map[flag][j])
map[0][j]=map[flag][j];
}
}
if(i==n)
printf("%d\n\n",sum);
else
printf("impossible\n\n");
}
}

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

  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. Ice_cream’s world III(prime)

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

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

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

  4. 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 ...

  5. A - Ice_cream’s world III

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

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

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

  7. Ice_cream’s world III--2122

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

  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. div自动适应浏览器窗口水平和垂直居中

    html <body> <div id="centerDiv">自动适应水平和垂直居中</div> </body> css ;;} ...

  2. Django models 常用字段类型

    1.CharField字符串字段,存较短的字符串,长文本要用TextField.必须的参数:max_length 字符的最大长度2.TextField容量很大的文本字段.admin中用 <tex ...

  3. android中复制图片

    activity_main.xml中的配置 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  4. js 事件冒泡、事件捕获、stopPropagation、preventDefault

    转自:http://www.jb51.net/article/42492.htm (1)冒泡型事件:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: ...

  5. Java_Web之俱乐部会员信息管理系统

    使用 Jsp实现俱乐部会员信息管理功能,orac1e11g作为后台数据库,该系统包括查看俱乐部会员信息列表和修改俱乐部会员信息两人功能,具体耍求如下: 打开俱乐部会员信息列表页面,以列表方式显示所有俱 ...

  6. SQL Server之十大存储过程

    下面介绍十大不同类型存储过程. 用户自定义存储过程 . 创建语法 create proc | procedure pro_name [{@参数数据类型} [=默认值] [output], {@参数数据 ...

  7. Android读写文件

    1.从resource中的raw文件夹中获取文件并读取数据(资源文件只能读不能写) String res = ""; try{ InputStream in = getResour ...

  8. ASP.NET MVC5 网站开发实践(一)

    一.开发环境 1.开发环境: Visual Studio 2013 2.数据库:Sql Server 2012 3.代码管理:TFS(微软免费提供的) 说明:VS2013与vs2012感觉变化不大,我 ...

  9. EF MySql:Specified key was too long; max key length is 767 bytes解决方案

    [DbConfigurationType(typeof(MySqlEFConfiguration))]//添加特性 public partial class Model1 : DbContext { ...

  10. Type inference

    Type inference refers to the automatic detection of the data type of an expression in a programming ...