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 iphone5屏幕适配 autosizing
转自:http://blog.sina.com.cn/s/blog_a843a8850101jxhh.html iphone5出来了,从不用适配的我们也要像android一样适配不同分辨率的屏幕了. ...
- Cassandra目录
1. cassandra安装 2. 过滤文本文档中的数据并插入Cassandra数据库 3. 用Java实现向Cassandra数据库中插入和查询数据 4. Cassandra在CQL语言层面支持多种 ...
- 实例源码--Android图片滚动切换效果
下载源码 技术要点: 1.图片滚动切换技术 2.详细的源码注释 ...... 详细介绍: 1.图片滚动切换技术 本套源码实现了类似于网站图片滚动推广效果,效果不错,很不错的参考源码 2.源码目录 运 ...
- 标准库 - fmt/print.go 解读
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...
- MySQL ALTER语法的运用方法 && 操作索引和字段
语法:alter_specification: ADD [COLUMN] create_definition [FIRST | AFTER column_name ] or ADD INDEX [in ...
- 《嵌入式Linux基础教程学习笔记一》
常用书目下载地址:http://www.cnblogs.com/pengdonglin137/p/3688029.html 第二章 1.进程上下文和中断上下文(Page20) 当应用程序执行系统调用, ...
- label
label的使用 以前只知道使用并没太注意一些细节 话说<label><input type="checkbox"/>5星</label>就可以 ...
- 监控服务器JVM内存运行
使用jdk的jconsole进行监控jmx 首先,设置监控对象的端口 配置 catalina.sh #vi /usr/tomcat/bin/catalina.sh 注: /usr/tomcat/b ...
- mysql_DML_update
update 表名 set 字段=XX where....;(记得加条件不安全改了) 多个字段: update 表名 set 字段1=XX,字段2= where....;(记得加条件不安全 ...
- 索引与优化like查询
1. like %keyword 索引失效,使用全表扫描.但可以通过翻转函数+like前模糊查询+建立翻转函数索引=走翻转函数索引,不走全表扫描. 2. like keyword% 索引有 ...