题目链接: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+超级汇点的更多相关文章

  1. HDU 3665 Seaside (最短路,Floyd)

    题意:给定一个图,你家在0,让你找出到沿海的最短路径. 析:由于这个题最多才10个点,那么就可以用Floyd算法,然后再搜一下哪一个是最短的. 代码如下: #pragma comment(linker ...

  2. hdoj 3572 Task Schedule【建立超级源点超级汇点】

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. 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 ...

  4. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  5. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  6. hdu 1869 (Floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory ...

  7. HDU 1217 Arbitrage (Floyd)

    Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...

  8. poj 1459 Power Network【建立超级源点,超级汇点】

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 25514   Accepted: 13287 D ...

  9. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

随机推荐

  1. [转]SQL快速入门

    原文出处:http://blog.csdn.net/xxd851116/article/details/5688263 一.基础 1.说明:创建数据库CREATE DATABASE database- ...

  2. 排序命令sort

    Unix和Linux自带的sort命令功能非常强大,其主要功能是对文本内容按不同的方法排序.它不仅可以按一个或多个字段排序,还可以合并文件.使用sort处理一些较大的文件时,可能处理速度会比较慢,但却 ...

  3. 浅谈 qmake 之 pro、pri、prf、prl文件

    尽管每次和cmake对比起来,我们总是说 qmake 简单.功能少.但是qmake仍然是一个非常复杂的东西,我想大多人应该和我一样吧: 不是太清楚CONFIG等变量到底如何起作用的 用过的qmake内 ...

  4. CentOS 6.4 离线安装 Cloudera 5.7.1 CDH 5.7.1

    因为项目开发需要要在本地组建一个Hadoop/Spark集群,除了Hadoop/Spark还要同时安装多个相关的组件,如果一个个组件安装配置,对于一个由多台服务器组成的集群来说,工作量是巨大的. 所以 ...

  5. redis 简介

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集(diff ...

  6. Border绘制虚线框(转)

    <Grid> <Border HorizontalAlignment="Center" VerticalAlignment="Center" ...

  7. jquery 请求apache solr 跨域解决方案

    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> ...

  8. mysql 查看表记录新增、修改的时间

    ALTER TABLE `tableName` ADD `updateAt` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP; ALTER TABLE kd_up ...

  9. react-redux-react-router直通车

    简单说明 这篇文章是我学习react一个多月来的总结,从基础开始(包括编辑器设置,构建工具搭建),一步一步走向react开发.相信我,看完这篇文章,跟着文章的步骤走,保证让你入门react并爱上rea ...

  10. 【Shell脚本学习17】Shell case esac语句

    case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...