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.  ≤ N ≤ ,  ≤ M ≤ N*(N-)/. The cities are markedwith numbers from  to N, Mirko is located in city , and Marica in city N.
In the next M lines are three numbers A, B and V, separated by commas. ≤ A,B ≤ N, ≤ V ≤ .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

 
Sample Output

 
Source

题意:城市内有n条路,其中有某条路在修,因为这条路有很多情况,问各种情况下的最短路中最长的是哪条

思路:直接枚举最短路的所有边,将边标记为inf,再跑dijkstra算出最大值即可

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
int dirx[]={,,-,};
int diry[]={-,,,};
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1006
#define inf 1<<26
int n,m;
int mp[N][N];
int fa[N];
void init(){
for(int i=;i<=n;i++){
fa[i]=-;
for(int j=;j<=n;j++){
if(i==j){
mp[i][j]=;
}
else{
mp[i][j]=inf;
}
}
}
}
int dijkstra(int flag){
int vis[N];
int dis[N];
for(int i=;i<=n;i++){
vis[i]=;
dis[i]=inf;
}
vis[]=;
dis[]=;
int x=n;
int st=;
while(x--){
for(int i=;i<=n;i++){ if(dis[i]>dis[st]+mp[st][i]){
dis[i]=dis[st]+mp[st][i];
if(flag){
fa[i]=st;
}
} }
int minn=inf;
for(int i=;i<=n;i++){
if(!vis[i] && dis[i]<minn){
minn=dis[i];
st=i;
}
}
vis[st]=; } return dis[n];
}
int main()
{
while(scanf("%d%d",&n,&m)==){
init();
for(int i=;i<m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(mp[a][b]>c){
mp[a][b]=mp[b][a]=c;
}
}
int ans=dijkstra(); for(int i=n;i!=;i=fa[i]){
int num=mp[i][fa[i]];
mp[i][fa[i]]=mp[fa[i]][i]=inf;
int cnt=dijkstra(); ans=max(ans,cnt);
mp[i][fa[i]]=mp[fa[i]][i]=num;
}
printf("%d\n",ans); }
return ;
}

hdu 1595 find the longest of the shortest(dijkstra)的更多相关文章

  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. hdu 1595 find the longest of the shortest

    http://acm.hdu.edu.cn/showproblem.php?pid=1595 这道题我用spfa在枚举删除边的时候求最短路超时,改用dijkstra就过了. #include < ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1595 大致题意: 给一个图.让输出从中删除随意一条边后所得最短路径中最长的. . 思路: 直接枚举每条边想必是不 ...

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

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

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

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

  8. hdu 1595(最短路变形好题)

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

  9. HDU 5373(2015多校7)-The shortest problem(模拟%11)

    题目地址:pid=5373">HDU 5373 题意:给你一个数n和操作次数t,每次操作将n的各位数之和求出来放在n的末尾形成新的n,问t次操作后得到的n能否够被11整除. 思路:就是 ...

随机推荐

  1. Unity 定时开启/关闭外部应用

    自从加入工作的队伍里,博客都荒废了,今天周末,难得清静,写篇博客!刚才看到了Process类,随手写了个小demo.给大家分享下! 首先大家要对Process类有一些简单的了解,参考资料:https: ...

  2. ArrayList的分析(转)

    一. ArrayList概述: ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,类似于C语言中的动态申请内存,动态增长内存. ArrayList不是线程安全的,只能用在单线程环境 ...

  3. Java内存区域和GC机制篇

    Java内存区域和GC机制一.目录 1.Java垃圾回收概括 2.Java内存区域 3.Java对象的访问方式 4.Java内存访问机制 5.Java GC 机制 6.Java垃圾收集器 二.Java ...

  4. fuser:用文件或者套接口表示进程

    fuser:用文件或者套接口表示进程 作用:fuser命令用文件或者套接口表示进程. 用法:fuser [-a | -s | -c] [-4 | -6] [-n space] [-k [-i] [-s ...

  5. HTTP协议4之缓存--转

    HTTP协议提供了非常强大的缓存机制, 了解这些缓存机制,对提高网站的性能非常有帮助. 缓存的概念 缓存这个东西真的是无处不在, 有浏览器端的缓存, 有服务器端的缓存,有代理服务器的缓存, 有ASP. ...

  6. 用CSS画五角星

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  7. oracle安装、配置、卸载、错误解决

    oracle安装卸载的帖子很多,这里整理出一份,都只是给出一个链接,忘了时可以自己看看.哈哈,其实我也觉得已经不会忘了,被这个鸡毛问题困了两天,修改控制文件.环境变量.注册表什么的都不能解决问题,最后 ...

  8. 网页body中background在ie中显示不出来

    网页body中background在ie中显示不出来 | 浏览:349 | 更新:2014-03-11 14:03 刚才上班在公司网站上写一个页面,在谷歌浏览器,火狐浏览器里调试完后,一切正常,忽然想 ...

  9. android设置图片变化的四种效果代码

    activity代码如下: package com.example.chapter12_graphic_animation; import android.os.Bundle; import andr ...

  10. (转) 学习C++ -> 指针初步

    学习C++ -> 指针初步 一.指针    1. 什么是指针?        我们知道, 计算机的内存是由一个个独立的存储单元组成, 并且系统会对每一个存储单元分配一个唯一的号码, 称为这个存储 ...