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 ...
随机推荐
- iOS开发——语法OC篇&BOOL / bool / Boolean / NSCFBoolean
Name Typedef Header True Value False Value BOOL signed char objc.h YES NO bool _Bool (int) stdbool.h ...
- SQL Server 2008 清空删除日志文件
USE [master]GOALTER DATABASE STAR9SQL SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE STAR9SQL SET ...
- WCF关于VS2010的配置
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE 下的 devenv.exe.config 在 <configura ...
- Android实现XML解析技术
转载:Android实现XML解析技术 本文介绍在Android平台中实现对XML的三种解析方式. XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为 ...
- redis的实现过程
1下载redis的安装包并按照操作安装 2开启 右击我的电脑→管理→服务→站到redis service服务 将其开启 注意:redis服务开启后其默认的ip和端口号为127.0.0.1:6379 3 ...
- Golang学习 - io 包
------------------------------------------------------------ 先说一下接口,Go 语言中的接口很简单,在 Go 语言的 io 包中有这样一个 ...
- 全栈一路坑之使用django创建博客
最近在看一篇全栈增长工程师实战,然后学习里面的项目,结果发现作者用的技术太过老旧,好多东西都已经被抛弃了,所以结合着官方文档和自己的一些理解将错误的信息替换一下,边写边学习 准备工作和工具 作者说需要 ...
- __KERNEL__ macro
转载:http://blog.csdn.net/kasalyn/article/details/17097639 The __KERNEL__ macro is defined because the ...
- 用vim处理字符的大小写转换
转载: http://blog.csdn.net/ruixj/article/details/3765385 http://www.linuxsong.org/2010/09/vim-convert- ...
- js的2种继承方式详解
js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 复制代码代码如下: function Person(name){ ...