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. Oracle存储1.1

    1.生成一个表的简单sql语句 CREATE OR REPLACE PROCEDURE proc_AutoGenerateSQL(  tableName   VARCHAR2 ,--参数 需要操作的表 ...

  2. Django项目:CRM(客户关系管理系统)--07--03PerfectCRM创建基本数据02

    from django.conf.urls import url from DBadd import auth_views from DBadd import crm_views urlpattern ...

  3. 介绍vue项目中的axios请求(get和post)

    一.先安装axios依赖,还有qs依赖 npm install axios --save npm install qs --save qs依赖包用post请求需要用到的 插入一个知识点: npm in ...

  4. python中函数和方法区别,以及如何给python类动态绑定方法和属性(涉及types.MethodType()和__slots__)

    网上有很多同义但不同方式的说法,下面的这个说法比较让你容易理解和接受 与类和实例无绑定关系的function都属于函数(function): 与类和实例有绑定关系的function都属于方法(meth ...

  5. Unicode, UTF-8, GBK, ASCII的区别

    看完知乎的两篇文章大概就明白了 https://zhuanlan.zhihu.com/p/25435644 https://www.zhihu.com/question/23374078 看完总结一下 ...

  6. JavaScript--返回顶部方法:锚链接、行内式js写法、外链式、内嵌式

    返回网页顶部方法 一.锚链接 simpleDemo: <!DOCTYPE html> <html lang="en"> <head> <m ...

  7. 连接池c3p0

    连接池c3p0 C3P0:hibernate和spring使用,有自动回收空闲连接的功能. 使用步骤: 1.导入jar包(c3p0-0.9.1.2.jar) 2.使用api a.硬编码(不推荐) ne ...

  8. pl/sql进阶一控制结构

    在任何计算机语言(c,java,c#,c++)都有各种控制语句(条件语句,循环结构,顺序控制结构…),在pl/sql中也存在这样的控制结构. 在本部分学校完毕后,希望大家达到: 1)使用各种if语句 ...

  9. Pycurl介绍

    pycurl — A Python interface to the cURL library Pycurl包是一个libcurl的Python接口.pycurl已经成功的在Python2.2到Pyt ...

  10. Libevent:1前言

    一:libevent概述: libevent是一个用来编写快速.可移植.非阻塞IO程序的库,它的设计目标是:可移植性.高效.可扩展性.便捷. libevent包含下列组件: evutil:对不同平台下 ...