//给一个无向图,问删除一条边,使得从1到n的最短路最长
//问这个最长路
//这个删除的边必定在最短路上,假设不在。那么走这条最短路肯定比其它短
//枚举删除这条最短路的边,找其最长的即为答案
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 1110 ;
const int inf = 0x3f3f3f3f;
struct Edge
{
int u , v , w ;
int next ;
}edge[maxn*maxn] ;
int head[maxn] ;
int nedge ;
int F[maxn] ;
int vis[maxn] ;
int dis[maxn] ;
int a[maxn] ;
int n , m;
void addedge(int u , int v , int w)
{
edge[nedge].u = u ;
edge[nedge].v = v ;
edge[nedge].w = w ;
edge[nedge].next = head[u] ;
head[u] = nedge++ ;
} void dijkstra(int num)
{
memset(vis , 0 , sizeof(vis)) ;
for(int j = 2;j <= n;j++)
dis[j] = inf ;
dis[1] = 0 ;
while(1)
{
int mi = inf; int pos ;
for(int j = 1 ;j <= n;j++)
if(!vis[j] && dis[j] < mi)
mi = dis[pos = j] ;
if(mi == inf)break;
vis[pos] = 1 ;
for(int i = head[pos] ;i != -1 ;i = edge[i].next)
{
if(i == num || i == (num^1))
continue ;
int v = edge[i].v;
if(dis[v] > dis[pos] + edge[i].w)
{
dis[v] = dis[pos] + edge[i].w ;
F[v] = i ;
}
}
}
}
int main()
{
//freopen("in.txt" ,"r" , stdin) ;
while(~scanf("%d%d" , &n , &m))
{
memset(head , -1 , sizeof(head)) ;
nedge = 0 ;
memset(F , 0 , sizeof(F)) ;
while(m--)
{
int u , v , w ;
scanf("%d%d%d" ,&u , &v ,&w) ;
addedge(u , v , w) ;
addedge(v , u , w) ;
}
dijkstra(nedge) ;
int u = n ;
int ans = 0 ;
int len = 0 ;
while(1)
{
if(u == 1)break ;
a[++len] = F[u] ;
u = edge[F[u]].u ;
}
for(int i = 1;i <= len;i++)
{
dijkstra(a[i]) ;
ans = max(ans , dis[n]) ;
}
cout<<ans<<endl;
}
return 0 ;
}

hdu1595find the longest of the shortest 最短路的更多相关文章

  1. 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 ...

  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. hdu1595 find the longest of the shortest(Dijkstra)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1595 find the longest of the shortest Time Limit: 100 ...

  4. find the longest of the shortest (hdu 1595 SPFA+枚举)

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

  5. HDU-1595Find the longest of shortest(最短路径的最长路Dijkstra+记录路径)

    Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she do ...

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

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

  7. 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 ...

  8. HDU1595-find the longest of the shortest-dijkstra+记录路径

    Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she do ...

  9. SGU 185 Two shortest 最短路+最大流

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21068 Yesterday Vasya and Petya qua ...

随机推荐

  1. 命令框中oracle dmp文件的导入和导出(仅做个人备忘)

    1.dmp文件导出 (全部)exp 用户名/密码 rows=y indexes=n compress=n buffer=65536 feedback=100000  file=F:\test.dmp ...

  2. Python三方库xlrd,xlwd-Excel读写

    恩,我是翻译汪,主要内容来自http://www.python-excel.org/ 在xlrd,xlwt这两个库中,Excel的结构表示为workbook整个Excel对象,sheet工作表,row ...

  3. Ubuntu下获取内核源码

    查看当前系统使用的内核版本: apt-cache search linux-source 输出如下: linux-source - Linux kernel source with Ubuntu pa ...

  4. tidyverse生态链

    一套完整的数据分析流程 , 如下图所示 从图中可以看到,整个流程包括读取数据,整洁数据,数据探索和交流部分.经过前两部分, 我们可以得到一个整理好的数据,它的每一行都是一个样本 , 每一列是一个变量. ...

  5. Python 之scrapy框架58同城招聘爬取案例

    一.项目目录结构: 代码如下: # -*- coding: utf-8 -*- # Define here the models for your scraped items # # See docu ...

  6. Xamarin.Forms实现touch事件

    Xamarin.Forms的View没有touch事件,只能自己实现 首先,在共享项目里面,放入这几个类,结构大概是这样的: using System; using Xamarin.Forms; na ...

  7. Java切换JDK版本的方法及技巧

    由于项目的不同安排,之前项目开发时,使用的jdk版本为1.8,现临时接手一以前项目,需要更换jdk版本. 安装 不再赘述,去Oracle网站(https://www.oracle.com/techne ...

  8. POJ 1088 滑雪(简单的记忆化dp)

    题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...

  9. 发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的

     table ID="zhutiTable" html2="<tr></tr>": 的数据 setTableInnerHTML(docu ...

  10. HDU1465 不容易系列之一&&HDU4535吉哥系列故事——礼尚往来

    HDU1465不容易系列之一 Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加 ...