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. The 4th tip of DB Query Analyzer

    The 4th tip of DB QueryAnalyzer Ma Genfeng (Guangdong Unitoll Services incorporated, Guangzhou 51030 ...

  2. Node.js-require的使用方法

    require最常用的方法 require('http') 内置模块 require('./server')  “./”表示当前路径,后面跟的是相对路径 require("../lib/se ...

  3. JAVA中常用需要设置的三个环境变量(JAVA_HOME、CLASSPATH、PATH)

    JAVA中常用需要设置的三个环境变量: JAVA_HOME.CLASSPATH.PATH (一) 配置环境变量:(相对路径) 1. JAVA_HOME=x:/jdk1.6.0 2. 用%JAVA_HO ...

  4. JSP通过SmartUpload上传文件实例

    httpRequest.setCharacterEncoding("gbk"); String preName = genName.doMake();//设置文件前缀名 Strin ...

  5. [Hapi.js] Up and running

    hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...

  6. Android 打造自己的个性化应用(三):应用程序的插件化

    在android的项目开发中,都会遇到后期功能拓展增强与主程序代码变更的现实矛盾,也就是程序的灵活度. 由于linux平台的安全机制,再加上dalvik的特殊机制,各种权限壁垒,使得开发一个灵活多变的 ...

  7. [Spring入门学习笔记][maven]

    什么是maven? 我的理解: 一个项目有一大堆依赖包的时候,没必要下下来,可以利用maven中的pom.xml 指定需要那些依赖包,让maven去本地中央库(如果没找到)->网上仓库库帮你调用 ...

  8. ios 网络数据下载和JSON解析

    ios 网络数据下载和JSON解析 简介 在本文中笔者将要给大家介绍ios中如何利用NSURLConnection从网络上下载数据,如何解析下载下来的JSON数据格式,以及如何显示数据和图片的异步下载 ...

  9. ubuntu 快捷图标

    ubuntu的图标都存在 /usr/share/applications下 图标是Desktop的后缀 首先gedit /usr/share/applications/xx.Desktop xx为应用 ...

  10. 安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项

    安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项,如下图所示 ...