HDU - 2833 - WuKong
先上题目:
WuKong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1070 Accepted Submission(s): 384
One day, Wukong left his home - Mountain of Flower and Fruit, to the Dragon King’s party, at the same time, Tang Monk left Baima Temple to the Lingyin Temple to deliver a lecture. They are both busy, so they will choose the shortest path. However, there may be several different shortest paths between two places. Now the Buddha wants them to encounter on the road. To increase the possibility of their meeting, the Buddha wants to arrange the two routes to make their common places as many as possible. Of course, the two routines should still be the shortest paths.
Unfortunately, the Buddha is not good at algorithm, so he ask you for help.
The input are ended with N=M=0, which should not be processed.
#include <cstdio>
#include <cstring>
#define max(x,y) (x > y ? x : y)
#define MAX 302
#define INF 1000000000
using namespace std; int dis[MAX][MAX],dp[MAX][MAX];
int n,m; void flyod(){
for(int u=;u<=n;u++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dis[i][j]>dis[i][u]+dis[u][j]){
dis[i][j]=dis[i][u]+dis[u][j];
dp[i][j]=dp[i][u]+dp[u][j];
}else if(dis[i][j]==dis[i][u]+dis[u][j]){
dp[i][j]=max(dp[i][u]+dp[u][j],dp[i][j]);
}
}
}
}
} int main()
{
int a,b,l;
int s1,e1,s2,e2;
int ans;
//freopen("data.txt","r",stdin);
while(scanf("%d %d",&n,&m),(n+m)){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
dis[i][j]= i==j ? : INF;
dp[i][j]=;
}
}
for(int i=;i<m;i++){
scanf("%d %d %d",&a,&b,&l);
if(dis[a][b]>l){
dis[a][b]=dis[b][a]=l;
dp[a][b]=dp[b][a]=;
}
} scanf("%d %d %d %d",&s1,&e1,&s2,&e2);
flyod();
ans=-;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dp[i][j]>ans && (dis[s1][e1] == dis[s1][i]+dis[i][j]+dis[j][e1])
&& (dis[s2][e2] == dis[s2][i]+dis[i][j]+dis[j][e2]) ){
ans=dp[i][j];
}
}
}
printf("%d\n",ans+);
}
return ;
}
2833
HDU - 2833 - WuKong的更多相关文章
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- 最短路&查分约束
[HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...
- HDU 5025:Saving Tang Monk(BFS + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description <Journey to ...
- hdu 3635 Dragon Balls (带权并查集)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
随机推荐
- bzoj2132: 圈地计划(无比强大的最小割)
2132: 圈地计划 题目:传送门 简要题意: 给出一个矩阵,一共n*m个点,并给出三个收益矩阵.A矩阵表示这个点建A的可取收益,B矩阵表示这个点建B的可取收益,C矩阵表示如果相邻(有且仅有一条公共边 ...
- 快速排序及三向切分快排——java实现
快速排序也是一种分治算法.主要思想是选取一个切分点,将大于切分点的元素都放置到数组右侧,小于切分点的元素都放置到数组左侧:然后递归,再对切分点左侧和右侧分别排序. 归并排序时递归在前,归并在后,快速排 ...
- Coursera Algorithms Programming Assignment 2: Deque and Randomized Queue (100分)
作业原文:http://coursera.cs.princeton.edu/algs4/assignments/queues.html 这次作业与第一周作业相比,稍微简单一些.有三个编程练习:双端队列 ...
- C/C++中的位运算符
--------开始-------- 我自己都记不住这是第几次把这几个位运算符搞混了,刚好在刚用过来把这几个位运算符记下来,俗话说的好好记性不如个烂笔头. 运算符: 与 或 ...
- 树莓派-USB存储设备自动挂载
简单介绍实现命令行下USB存储设备自动挂载的方法,Linux gnome/kde窗口环境下有移动存储的管理程序,可以实现自动挂载移动存储设备,但是在命令行下 通常需要用mount命令手动挂载USB存储 ...
- bitmap实现背景透明
近日在项目中,一直被一个问题搞得头大的很,美工要把按钮图片弄成不规则的,但是在winform里实现又不仅仅是使用简单的png图片而已.在网上找到一些方法,稍微改了一点加工成项目所需. 贴出解决方案,以 ...
- python--7、面向对象
什么是面向对象 对象,即抽象的一类事物中的某个具体的个体.这个世界中存在的一切皆为对象,不存在的也能创建出来. 较之面向过程的区别: 编程的复杂度远高于面向过程,不了解面向对象而立即上手基于它设计程序 ...
- ArrayList 源码
1.ArrayList的类关系: 2.属性及方法 2.1 构造 三个构造方法分别对应: 通过传入初始化容器大小构造数组列表 ...
- IE浏览器发展史
- Newtonsoft.Json 处理日期格式
Newtonsoft.Json.Converters.IsoDateTimeConverter iso = new Newtonsoft.Json.Converters.IsoDateTimeConv ...