//给一个无向图,问删除一条边,使得从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. flask 初始

    一.flask安装 这里提供两种安装方式: 第一种: pip3 install flask 第二种: pip3 install -i https://pypi.douban.com/simple/ f ...

  2. ACM_出题人这样不好吧

    出题人这样不好吧 Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为编协的第一次月赛,肯定是要有防AK(ALL KILL)的题目 ...

  3. linux命令大杂烩之网络管理

    在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具. 作为一款强力 ...

  4. servlet-有参数的init和无参的init方法

    package gz.itcast.d_init; import javax.servlet.ServletConfig; import javax.servlet.ServletException; ...

  5. C# 设定时间内自动关闭提示框

    通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net framework 没有为我们提供自动关闭MessageBox 的方法,要实现这个功能,我们需要使用Window API ...

  6. unable to get system library for the project

    当向eclipse导入项目实例后,项目上出现红叉的错误提示,在项目属性里的Java Build Path里发现了错误提示复选选项: unable to get system library for t ...

  7. zoom,zoom与haslayout的关系,zoom与transform: scale( )的区别

    1.zoom:(缩放)

  8. 记录--git命令行上传项目到github仓库

    由于公司一直使用的是的SVN,基本上都是内网,原来的git命令都快忘记了,当然也是自己太懒,平时都是直接拖到github上.今天打开idea后突然看到了原来自己写好的一个项目,就想将它上传到githu ...

  9. javaWEB中web.xml配置文件相关

    1.常用节点的执行顺序: context-param -> listenter -> filter -> servlet -> interceptor,其中有多个filter的 ...

  10. mapbox-gl 使用ArcGISServer 发布的栅格切片

    最近使用mapbox 进行数据化展现.刚好用到了超图平台在去三维系统,顺带就用超图平台发布了栅格切片,用来做底图,但是超图平台是试用的许可,栅格切片有SuperMap 的水印,实在不雅观. 在网上搜索 ...