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. NOIP模拟17.9.21

    NOIP模拟17.9.21 3 58 145 201 161.5 样例输出21.6 数据规模及约定对于40% 的数据,N <= 20对于60% 的数据,N <= 1000对于100% 的数 ...

  2. 洛谷P2912 [USACO08OCT]牧场散步Pasture Walking [2017年7月计划 树上问题 01]

    P2912 [USACO08OCT]牧场散步Pasture Walking 题目描述 The N cows (2 <= N <= 1,000) conveniently numbered ...

  3. 为什么我要使用Linux,使用Linux的十个理由。

    Linux一来都是做为服务器运行,这些年来,Linux的图形界面已经有了很大的改善,Linux已经成为一个完善的,用户友好的桌面操作系统了,有非多常多的人在使用Linux,下面是我们认为最必要的10个 ...

  4. fileinput URL携带参数的问题,uploadExtraData,Bootstrap

    因为无法在URL中执行其他代码,通过阅读文档可知可以由uploadExtraData参数携带数据.于是在这里携带,如果uploadExtraData 无法接收到数据,一般是格式有误, 先尝试这个简单的 ...

  5. 【Codeforces Round #430 (Div. 2) B】Gleb And Pizza

    [链接]点击打开链接 [题意] 在这里写题意 [题解] 根据圆心到原点的距离这个东西判断一下圆在不在那个环里面就好 [错的次数] 0 [反思] 在这了写反思 [代码] #include <cst ...

  6. VMware workstation12安装苹果虚拟机

    一.前言--准备工作 在win10上安装Mac虚拟机,既是费劲又是费内存的活儿 1.安装Vmware 2.下载MacOS的镜像:自行百度下载 3. unlocker的下载地址:http://downl ...

  7. web前端学习(二)html学习笔记部分(9)-- 响应式布局

    1.2.23  响应式布局基础 1.2.23.1  响应式布局介绍 1.响应式布局是2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多终端 -- 而不是为每个终端做一个特定的版本.这个概 ...

  8. mac 下的 homebrew

    如果安装了macport 就不能安装homebrew ,必须先卸载macport $ sudo port -f uninstall installed$ sudo rm -rf \/opt/local ...

  9. 数据挖掘案例:基于 ReliefF和K-means算法的应用

    数据挖掘案例:基于 ReliefF和K-means算法的应用 数据挖掘方法的提出,让人们有能力最终认识数据的真正价值,即蕴藏在数据中的信息和知识.数据挖掘(DataMiriing),指的是从大型数据库 ...

  10. [Vue CLI 3] 配置解析之 indexPath

    在 vue.config.js 配置中有一个 indexPath 的配置,我们先看看它有什么用? 用来指定 index.html 最终生成的路径(相对于 outputDir) 先看看它的默认值:在文件 ...