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, ...
随机推荐
- Why is try {…} finally {…} good; try {…} catch{} bad?
http://stackoverflow.com/questions/128818/why-is-try-finally-good-try-catch-bad The big difference i ...
- LA4788
贪心 这个贪心不太懂啊 dfs返回子树需要的最小值,然后按需要减消耗排序,然后贪心选取即可. #include<bits/stdc++.h> using namespace std; ty ...
- WingIDE4.1 破解及支持中文设置
1.下面提供最新版本的破解方法. 先到http://wingware.com/downloads/wingide下载最新版本的IDE. 安装之前,先修改时间到一个月前. 安装 安装之后然后获取试用版的 ...
- javascript--给你的JS代码添加单元测试
通过测试框架为JavaScript应用添加测试,从而保证代码的高质量.这里的笔记例子应用在jaywcjlove/validator.js中. 安装 用到三个工具chai(断言工具),mocha(测试框 ...
- 0522 json
一.概念 json依赖于js和xml,是一种数据交换格式,json对比xml的生成和处理要更加方便.因此在许多领域,json正逐步取代xml的使用. 二.使用 1.在JS当中 json在javascr ...
- Oracle 12.2.0.1 RAC for rhel 7.X 数据库安装(节点1执行root.sh失败)
说明: 最开始是用的rehat7.2安装12.2.0.1,后面安装GI节点一执行root.sh脚本失败,排查原因,最开始以为是操作系统的问题,换成rehat7.6,同样的出现问题,经过一番折腾,后面通 ...
- C - Stones on the Table
Problem description There are n stones on the table in a row, each of them can be red, green or blue ...
- asp.net限制了上传文件大小为..M,解决方法
asp.net限制了上传文件大小为4M,在:在web.config里加下面一句,加在<System.web></System.web>之间如下:<system.web&g ...
- Java实现九宫格
import java.util.Scanner; public class Sudoku { public static void main(String[] args) { System.out. ...
- 1、Scala安装与基础
1.scala与java 2.安装 3.scala编译器 4.变量声明 5.数据类型 6.操作符 7.函数调用 8.apply函数 1.scala与java scala基于java虚拟机,所有scal ...