题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3665

题意分析:以0为起点,求到Sea的最短路径。 所以可以N为超级汇点,使用floyd求0到N的最短路径。

/*SeasideTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1151    Accepted Submission(s): 839Problem 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 1Sample Output
2Source
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 = 100 + 10;
#define INF 1000001
int m[maxn], p[maxn], d[maxn][maxn];void init()
{for(int i = 0; i < maxn; i++)for(int j = 0; j < maxn; j++)if(i == j) d[i][j] = 0;else d[i][j] = INF;
}int main()
{int n, s, l;while(~scanf("%d", &n)){init();for(int i = 0; i < n; i++){scanf("%d%d", &m[i], &p[i]);if(p[i]) d[i][n] = 0;for(int j = 0; j < m[i];j++){scanf("%d%d", &s, &l);d[s][i] = d[i][s] = l;}}for(int k = 0; k <= n; k++)for(int i = 0; i <= n; i++)for(int j = 0; j <= n; j++)d[i][j] = min(d[i][j], d[i][k]+d[k][j]);printf("%d\n", d[0][n]);}return 0;
}

转载于:https://www.cnblogs.com/ACFLOOD/p/4299323.html

hdu 3665 Seaside floyd+超级汇点相关推荐

  1. HDU 3665 Seaside

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=3665 Problem Description XiaoY is living in a ...

  2. HDU 3665 Seaside(Dijkstra)

    题目链接 区域赛的水题...题意理解好了就OK了,模版题,还是调试了一会,自己对代码不太熟练啊. 1 #include <stdio.h> 2 #include <string.h& ...

  3. 图论技巧 : 超级源点与超级汇点的建立

    1.什么是超级源点与超级汇点 (1)超级源点跟超级汇点是模拟出来的虚拟点,多用于图中 : <1>同时有多个源点和多个汇点,建立超级源点和超级汇点 <2>同时有多个源点和一个汇点 ...

  4. 【HDU No. 4417】 超级马里奥 Super Mario

    [HDU No. 4417] 超级马里奥 Super Mario 杭电OJ 题目地址 [题意] 可怜的公主陷入困境,马里奥需要拯救他的情人.把通往城堡的道路视为一条线(长度为n ),在每个整数点i 上 ...

  5. HDU 1217 Arbitrage (Floyd + SPFA判环)

    题目链接:HDU 1217 Arbitrage 简单的货币转换问题,给定多种货币,以及货币之间的汇率,问能否通过货币的转换实现收益. 例如: 1 US Dollar buys 0.5 British ...

  6. HDU2112 HDU Today【Floyd算法】

    HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. HDU -1704 Rank——floyd

  8. 8-12-COMPETITION

    链接:最短路 A.HDU 2544    最短路 算是最基础的题目了吧.............我采用的是Dijkstra算法....... 代码: 1 #include <iostream&g ...

  9. 《网络流学习笔记04 NYOJ 489 哭泣天使(建边,超级源点和汇点)》

    链接:click here 题意描述: 哭泣天使 时间限制: 1000 ms  |  内存限制: 65535 KB 难度: 5 描述 Doctor Who乘着Tardis带着Amy来到了一个星球,一开 ...

最新文章

  1. 【转】ubuntu下实用的三款录屏软件
  2. XXX语录,可以不信,但不能不看
  3. 方立勋_30天掌握JavaWeb_JavaBean、mvc开发模式、el表达式、jstl标签
  4. Unity3D学习笔记之九为场景添加细节(二)
  5. flannel无法跨主机ping通容器的解决方式
  6. 隐式类型转换中显式申明的非必要性
  7. (转)Spring Boot(十二):Spring Boot 如何测试打包部署
  8. php后台代码自动生成程序,Thinkphp自定义代码生成工具及用法说明(附下载地址)...
  9. request.getInputStream中文乱码解决方案
  10. python---单元测试
  11. 中国电信运营商布局云计算“赛道”面临三大挑战
  12. Head First 系列书籍分享,Head First Python (中文版·第2版),Head First Java(中文版):第二版——涵盖Java 5.0...
  13. cmd命令结束端口进程
  14. 隐马尔可夫模型基础介绍
  15. QT学习教程-(1)QT新建项目并打包hellow world
  16. 【对未来机器人的畅想】
  17. 通过mac地址查询ip
  18. 查看端口占用情况以及如何解除端口占用
  19. C#绘图工具之Redim
  20. h5页面excel转json

热门文章

  1. CSS实现水平居中的六种方法
  2. Python 入门学习10 —— 文件操作的应用及升级版三级菜单
  3. 【Addicted TO ROS】ROS工程结构
  4. Excel sumproduct用法
  5. 百度云之下载失败解决方案
  6. 主X的船长你走吧,我们能赢
  7. 【鲁棒】对信息不完整的 DSGE 模型进行鲁棒预测(Matlab代码实现)
  8. css 导航栏下划线跟随效果,默认第一个li为选中状态
  9. 新规出|一建证书公路与水利专业含金量上升
  10. 官宣!Databend 和 XSKY星辰天合达成合作