hdu 3665 Seaside floyd+超级汇点
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3665
题意分析:以0为起点,求到Sea的最短路径。 所以可以N为超级汇点,使用floyd求0到N的最短路径。
/*Seaside Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1151 Accepted Submission(s): 839 Problem Description
XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns are numbered from 0 to N-1 and XiaoY lives in the town numbered ’0’. There are some directed roads connecting them. It is guaranteed that you can reach any town from the town numbered ’0’, but not all towns connect to each other by roads directly, and there is no ring in this city. One day, XiaoY want to go to the seaside, he asks you to help him find out the shortest way. Input
There are several test cases. In each cases the first line contains an integer N (0<=N<=10), indicating the number of the towns. Then followed N blocks of data, in block-i there are two integers, Mi (0<=Mi<=N-1) and Pi, then Mi lines followed. Mi means there are Mi roads beginning with the i-th town. Pi indicates whether the i-th town is near to the sea, Pi=0 means No, Pi=1 means Yes. In next Mi lines, each line contains two integers SMi and LMi, which means that the distance between the i-th town and the SMi town is LMi. Output
Each case takes one line, print the shortest length that XiaoY reach seaside. Sample Input
5
1 0
1 1
2 0
2 3
3 1
1 1
4 100
0 1
0 1 Sample Output
2 Source
2010 Asia Regional Harbin */
//floyd: d[i][j] = min(d[i][j], d[i][k]+d[k][j])
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = + ;
#define INF 1000001
int m[maxn], p[maxn], d[maxn][maxn]; void init()
{
for(int i = ; i < maxn; i++)
for(int j = ; j < maxn; j++)
if(i == j) d[i][j] = ;
else d[i][j] = INF;
} int main()
{
int n, s, l;
while(~scanf("%d", &n)){
init();
for(int i = ; i < n; i++){
scanf("%d%d", &m[i], &p[i]);
if(p[i]) d[i][n] = ;
for(int j = ; j < m[i];j++){
scanf("%d%d", &s, &l);
d[s][i] = d[i][s] = l;
}
}
for(int k = ; k <= n; k++)
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
printf("%d\n", d[][n]);
}
return ;
}
hdu 3665 Seaside floyd+超级汇点的更多相关文章
- HDU 3665 Seaside (最短路,Floyd)
题意:给定一个图,你家在0,让你找出到沿海的最短路径. 析:由于这个题最多才10个点,那么就可以用Floyd算法,然后再搜一下哪一个是最短的. 代码如下: #pragma comment(linker ...
- hdoj 3572 Task Schedule【建立超级源点超级汇点】
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Seaside HDU 3665 【Dijkstra】
Problem Description XiaoY is living in a big city, there are N towns in it and some towns near the s ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1869 (Floyd)
http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- poj 1459 Power Network【建立超级源点,超级汇点】
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25514 Accepted: 13287 D ...
- HDU 4034 Graph(Floyd变形——逆向判断)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...
随机推荐
- stm32 IAP + APP ==>双剑合一
(扩展-IAP主要用于产品出厂后应用程序的更新作用,上一篇博文详细的对IAP 升级程序做了详细的分析http://blog.csdn.net/yx_l128125/article/details/12 ...
- python 中sys.stdout.write 和 print >> sys.stdout的区别(转)
下面应该可以解你的惑了: print >> sys.stdout的形式就是print的一种默认输出格式,等于print "%VALUE%" 看下面的代码的英文注释,是p ...
- linux消息队列操作
对消息队列的操作无非有以下三种类型: 1. 打开或创建消息队列消息队列的内核持续性要求每一个消息队列都在系统范围内相应唯一的键值,所以,要获得一个消息队列的描写叙述字,仅仅需提供该消息队列的键值就可以 ...
- Mac下配置cocos2d-x开发环境(android和ios)
一.下载cocos2d-x http://cocos2d-x.org/projects/cocos2d-x/wiki/Download cocos2d-x-2.1.4.zip @ June.18, 2 ...
- Android开发目录
1.ADT下载地址整理 2.之前的Android项目报错,新建Android项目报错,代码中找不到错误解决方案 3.错误“Unexpected namespace prefix "xmlns ...
- RedHat Linux 安装oracle11g
1.准备oracle安装文件Oracle11gR2包含两个文件linux_11gR2_database_1of2.zip和linux_11gR2_database_2of2.zip,将这两个文件通过S ...
- NoSQL数据库的分布式算法&&memcache集群的实现
NoSQL数据库的分布式算法 http://blog.nosqlfan.com/html/4139.html 一致性hash算法在memcache集群中的应用 http://alunblog.d ...
- centos6.4使用man查找命令时,报错No manual entry for xxxx
前提:安装man的命令 yum -y install man 使用man报错 [root@localhost objs]# man fcntlNo manual entry for fcntl[roo ...
- Joy of Programming: Understanding Bit-fields in C
转:http://www.linuxforu.com/2012/01/joy-of-programming-understanding-bit-fields-c/ By S.G. Ganesh on ...
- android图片特效处理之模糊效果
这篇将讲到图片特效处理的模糊效果.跟前面一样是对像素点进行处理,算法是通用的,但耗时会更长,至于为什么,看了下面的代码你就会明白. 算法: 一.简单算法:将像素点周围八个点包括自身一共九个点的RGB值 ...