find the longest of the shortest

Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2702    Accepted Submission(s):
974

Problem Description
Marica is very angry with Mirko because he found a new
girlfriend and she seeks revenge.Since she doesn't live in the same city, she
started preparing for the long journey.We know for every road how many minutes
it takes to come from one city to another.
Mirko overheard in the car that
one of the roads is under repairs, and that it is blocked, but didn't konw
exactly which road. It is possible to come from Marica's city to Mirko's no
matter which road is closed.
Marica will travel only by non-blocked roads,
and she will travel by shortest route. Mirko wants to know how long will it take
for her to get to his city in the worst case, so that he could make sure that
his girlfriend is out of town for long enough.Write a program that helps Mirko
in finding out what is the longest time in minutes it could take for Marica to
come by shortest route by non-blocked roads to his city.
 
Input
Each case there are two numbers in the first row, N and
M, separated by a single space, the number of towns,and the number of roads
between the towns. 1 ≤ N ≤ 1000, 1 ≤ M ≤ N*(N-1)/2. The cities are markedwith
numbers from 1 to N, Mirko is located in city 1, and Marica in city N.
In the
next M lines are three numbers A, B and V, separated by commas. 1 ≤ A,B ≤ N, 1 ≤
V ≤ 1000.Those numbers mean that there is a two-way road between cities A and B,
and that it is crossable in V minutes.
 
Output
In the first line of the output file write the maximum
time in minutes, it could take Marica to come to Mirko.
 
Sample Input
5 6
1 2 4
1 3 3
2 3 1
2 4 4
2 5 7
4 5 1
 
6 7
1 2 1
2 3 4
3 4 4
4 6 4
1 5 5
2 5 2
5 6 5
 
 
5 7
1 2 8
1 4 10
2 3 9
2 4 10
2 5 1
3 4 7
3 5 10
 
Sample Output
11
13
27
 
Author
ailyanlu
 
Source
 
Recommend
8600   |   We have carefully selected several similar
problems for you:  1596 1598 1142 1162 1301 
 
枚举所有的路被删除的情况,用迪杰斯特拉求最短路。
 
题意:一个无向图,n个点,m条边,输入m条边的起点,终点,距离,假设减去其中任意一条边,问各种情况下的最短路中最长的是哪条
 
附上代码:
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#define M 1005
#define inf 0x3f3f3f3f
using namespace std;
int map[M][M],vis[M],dis[M],link[M];
int n,m;
int max(int a,int b)
{
return a>b?a:b;
} void djstl(int s,int flag) ///最短路遍历,s代表起点,flag作为标记,初始第一次为1,以后为0
{
int i,j,minn,t;
memset(vis,,sizeof(vis));
for(i=; i<=n; i++)
dis[i]=inf;
dis[s]=;
for(i=; i<=n; i++)
{
minn=inf;
for(j=; j<=n; j++)
if(!vis[j]&&dis[j]<minn)
{
minn=dis[j];
t=j;
}
vis[t]=;
for(j=; j<=n; j++)
{
if(!vis[j]&&map[t][j]<inf)
{
if(dis[j]>dis[t]+map[t][j])
{
dis[j]=dis[t]+map[t][j];
if(flag) ///这个点一定为一个缩短路程的转折点,去除后才会导致路程变长
{
link[j]=t;
} }
}
}
}
return;
} int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
memset(link,,sizeof(link));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
if(i==j) map[i][j]=;
else map[i][j]=inf;
int a,b,c;
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
if(map[a][b]>c)
map[a][b]=map[b][a]=c;
}
djstl(,); ///第一次初始化图,求出每个点的最短路
int ans=dis[n];
for(i=n; i!=; i=link[i])
{
int tem=map[i][link[i]];
map[i][link[i]]=map[link[i]][i]=inf; ///遍历去掉每条路的情况
djstl(,);
ans=max(ans,dis[n]);
map[i][link[i]]=map[link[i]][i]=tem;
}
printf("%d\n",ans);
}
return ;
}

hdu 1595 find the longest of the shortest(迪杰斯特拉,减去一条边,求最大最短路)的更多相关文章

  1. HDU 3790(两种权值的迪杰斯特拉算法)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    ...

  2. hdu 1595 find the longest of the shortest【最短路枚举删边求删除每条边后的最短路,并从这些最短路中找出最长的那条】

    find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  3. hdu 1595 find the longest of the shortest(dijkstra)

    Problem Description Marica is very angry with Mirko because he found a new girlfriend and she seeks ...

  4. hdu 1595 find the longest of the shortest

    http://acm.hdu.edu.cn/showproblem.php?pid=1595 这道题我用spfa在枚举删除边的时候求最短路超时,改用dijkstra就过了. #include < ...

  5. hdu 1595 find the longest of the shortest(dijstra + 枚举)

    http://acm.hdu.edu.cn/showproblem.php?pid=1595 大致题意: 给一个图.让输出从中删除随意一条边后所得最短路径中最长的. . 思路: 直接枚举每条边想必是不 ...

  6. HDU 1595 find the longest of the shortest【次短路】

    转载请注明出处:http://blog.csdn.net/a1dark 分析:经典的次短路问题.dijkstra或者SPFA都能做.先找出最短路.然后依次删掉没条边.为何正确就不证明了.了解思想直接A ...

  7. HDU 3339 In Action(迪杰斯特拉+01背包)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=3339 In Action Time Limit: 2000/1000 MS (Java/Others) ...

  8. HDU 2544最短路 (迪杰斯特拉算法)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2544 最短路 Time Limit: 5000/1000 MS (Java/Others)    Me ...

  9. HDU 1874畅通工程续(迪杰斯特拉算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 畅通工程续 Time Limit: 3000/1000 MS (Java/Others)     ...

随机推荐

  1. HDU 4280 Island Transport(dinic+当前弧优化)

    Island Transport Description In the vast waters far far away, there are many islands. People are liv ...

  2. select2 如何自定义提示信息-布布扣-bubuko.com

    标签:color   dom   layui   href   默认事件   替换   each   ase   options 最近项目中使用到了select2来美化和丰富下拉框的功能,这款插件功能 ...

  3. h5滚动页面固定导航

    1.需要效果 2.实现方法 (1)原生js实现 document.addEventListener('scroll', function (event) { var scrollDamo = wind ...

  4. 关于502 bad gateway报错的解决办法

  5. C++学习笔记----2.4 C++对象的内存模型

    转载自:http://c.biancheng.NET/cpp/biancheng/view/2995.html点击打开链接 当对象被创建时,编译器会为每个对象分配内存空间,包括成员变量和成员函数. 直 ...

  6. Python学习笔记(四)Python程序的控制结构

    在学习了 Python 的基本数据类型后,我们就要开始接触Python程序的控制结构,了解 Python 是如何使用控制结构来更改程序的执行顺序以满足多样的功能需求.如果有的小伙伴在之前学过C语言,j ...

  7. JSP页面中验证码的调用方法

    步骤: 1.首先是要生成验证码 2.对验证码类进行调用:主要 实现的是  将验证码图片 输出到response.getOutputStream()这个输出流中 调用时,可以在页面调用,也可以在serv ...

  8. SDUT-3402_数据结构实验之排序五:归并求逆序数

    数据结构实验之排序五:归并求逆序数 Time Limit: 50 ms Memory Limit: 65536 KiB Problem Description 对于数列a1,a2,a3-中的任意两个数 ...

  9. Liferay JSP Tag Libraries介绍

    Liferay自带了很多标签库,这极大地提高了开发Liferay项目的效率. 下面让我们一起来探索吧. 什么是标签库? 什么是JSP标签? 什么是JSTL? 标签库由下面这几部分组成: Tag Lib ...

  10. LintCode刷题笔记-- Count1 binary

    标签: 位运算 描述: Count how many 1 in binary representation of a 32-bit integer. 解题思路: 统计一个int型的数的二进制表现形式中 ...