hdu1595find the longest of the shortest 最短路
//给一个无向图,问删除一条边,使得从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 最短路的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 1595 find the longest of the shortest【次短路】
转载请注明出处:http://blog.csdn.net/a1dark 分析:经典的次短路问题.dijkstra或者SPFA都能做.先找出最短路.然后依次删掉没条边.为何正确就不证明了.了解思想直接A ...
- 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 ...
- 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 ...
- SGU 185 Two shortest 最短路+最大流
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21068 Yesterday Vasya and Petya qua ...
随机推荐
- Spring Cloud (10) Hystrix-监控面板
Hystrix DashBoard 断路器是根据一段时间窗内的请求状况来判断并操作断路器的打开和关闭状态的.Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界 ...
- RabbitMQ 创建用户和创建Virtual host
https://www.bilibili.com/video/av18997807/?p=3 Virtual host 就是类似数据库吧.
- React-Native WebView动态加载字体
背景 使用react-native构建的iOS/Android双端APP,通过WebView加载本地页面,需要根据服务器提供的字体列表实现下载和动态加载. 本地字体检查 有些字体手机操作系统已经提供了 ...
- AjaxDemo
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- ARM架构与体系学习(二)——3级流水线
ARM架构与体系学习(二)——3级流水线 标签: 存储嵌入式汇编c 2012-04-18 00:44 5414人阅读 评论(4) 收藏 举报 分类: ARM7(16) 版权声明:本文为博主原创文章 ...
- R语言图表
条形图 在R语言中创建条形图的基本语法是 barplot(H, xlab, ylab, main, names.arg, col) H是包含在条形图中使用的数值的向量或矩阵 xlab是x轴的标签 yl ...
- PAC代理语法含义与书写规范
一直以来使用ShadowSocksFQ,基本上默认的PAC代理模式己能满足所需,实在个别pac不方便的就转成用全局代理模式也能愉快FQ. 只是最近学习前端的知识,需要FQ访问 MDN web docs ...
- [数据结构】【c语言】链表的创建和遍历
第一次写代码的博客,一个刚刚接触的新手,来这里主要是为了记录自己,方便自己以后浏览,也欢迎大家指正.先来个简单的,动态链表的创建和遍历. #include<stdio.h> #includ ...
- Problem 63
Problem 63 https://projecteuler.net/problem=63 Powerful digit counts The 5-digit number, 16807=75, i ...
- 【IntelliJ IDEA】idea上安装Translation插件后,需要AppKey才能生效的解决方案
使用idea安装的翻译插件translation,但是使用的时候并不友好 无奈,如果想使用翻译软件并且更方便的话,可以如下: 可以选择将translation进行卸载 清除缓存并进行重启 然后再启动之 ...