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. Android开机图片替换

    Android开机图片替换 Android从启动到进入Launcher一共会展示三张图片,如果只是更换静态图则更换这三张图片即可,要想换成动画那就要另外操作. 首先查找这个文件:    /bootab ...

  2. mongoose 操作 mongodb 笔记 (自己的笔记,自己看的)

    mongodb下载/安装 mongoose   npm install --save mongoose mongoose 数据库连接 const mongoose = require('mongoos ...

  3. 如何写出高性能SQL语句(文章摘自web开发者)

    (声明:本文内容摘自web开发者,仅供收藏学习之用,如有侵权请作者联系博主,博主将在第一时间删除) 原文地址:http://www.admin10000.com/document/484.html 1 ...

  4. springboot 大致启动流程

    SpringApplication的run方法的实现是我们本次旅程的主要线路,该方法的主要流程大体可以归纳如下: 1) 如果我们使用的是SpringApplication的静态run方法,那么,这个方 ...

  5. PAT_A1147#Heaps

    Source: PAT A1147 Heaps (30 分) Description: In computer science, a heap is a specialized tree-based ...

  6. sqlserver系统表使用

    SELECT s.table_catalog as 数据库名, o.name as 表名, c.name as 列名FROM INFORMATION_SCHEMA.TABLES s,--库 sys.o ...

  7. Python笔记(29)----进程

    目录: 一.进程 多任务的概念 创建子进程----fork[Linux] 全局变量在多个进程中不共享 多次fork() 创建进程----multiprocessing[windows] 二.线程 一. ...

  8. PKU 1019 Number Sequence(模拟,思维)

    题目 以下思路参考自discuss:http://poj.org/showmessage?message_id=176353 /*我的思路: 1.将长串数分成一个个部分,每个部分是从1到x的无重复的数 ...

  9. sass使用中出现的问题

    问题一:ruby按照官方文档安装后更换gem源时,报错Error fetching https://gems.ruby-china.org/: bad response Not Found 404 ( ...

  10. Linux下进程与线程的区别

    https://www.cnblogs.com/fah936861121/articles/8043187.html https://my.oschina.net/cnyinlinux/blog/36 ...