Ice_cream’s world III
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
city to the capital. The project’s cost should be as less as better.
2 1
0 1 10 4 0
10 impossible
#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的更多相关文章
- hdoj 2122 Ice_cream’s world III
并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Ice_cream’s world III(prime)
Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- 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 ...
- 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 ...
- 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 ...
- 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 小希的迷宫 基 ...
随机推荐
- Android开机图片替换
Android开机图片替换 Android从启动到进入Launcher一共会展示三张图片,如果只是更换静态图则更换这三张图片即可,要想换成动画那就要另外操作. 首先查找这个文件: /bootab ...
- mongoose 操作 mongodb 笔记 (自己的笔记,自己看的)
mongodb下载/安装 mongoose npm install --save mongoose mongoose 数据库连接 const mongoose = require('mongoos ...
- 如何写出高性能SQL语句(文章摘自web开发者)
(声明:本文内容摘自web开发者,仅供收藏学习之用,如有侵权请作者联系博主,博主将在第一时间删除) 原文地址:http://www.admin10000.com/document/484.html 1 ...
- springboot 大致启动流程
SpringApplication的run方法的实现是我们本次旅程的主要线路,该方法的主要流程大体可以归纳如下: 1) 如果我们使用的是SpringApplication的静态run方法,那么,这个方 ...
- PAT_A1147#Heaps
Source: PAT A1147 Heaps (30 分) Description: In computer science, a heap is a specialized tree-based ...
- sqlserver系统表使用
SELECT s.table_catalog as 数据库名, o.name as 表名, c.name as 列名FROM INFORMATION_SCHEMA.TABLES s,--库 sys.o ...
- Python笔记(29)----进程
目录: 一.进程 多任务的概念 创建子进程----fork[Linux] 全局变量在多个进程中不共享 多次fork() 创建进程----multiprocessing[windows] 二.线程 一. ...
- PKU 1019 Number Sequence(模拟,思维)
题目 以下思路参考自discuss:http://poj.org/showmessage?message_id=176353 /*我的思路: 1.将长串数分成一个个部分,每个部分是从1到x的无重复的数 ...
- sass使用中出现的问题
问题一:ruby按照官方文档安装后更换gem源时,报错Error fetching https://gems.ruby-china.org/: bad response Not Found 404 ( ...
- Linux下进程与线程的区别
https://www.cnblogs.com/fah936861121/articles/8043187.html https://my.oschina.net/cnyinlinux/blog/36 ...