find the longest of the shortest

Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3990    Accepted Submission(s): 1498

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

6 7
1 2 1
2 3 4
3 4 4
4 6 4
1 5 5
2 5 2
5 6 5

5 7
1 2 8
1 4 10
2 3 9
2 4 10
2 5 1
3 4 7
3 5 10

 
Sample Output
11
13
27
 
Author
ailyanlu
 
Source
    最近一直1A我有点方啊。。。
   题意是某个渣男貌似为了想让女友更晚的回来,要求选择一条路关闭,换言之就是删除一条边之后最短路的最大值,但是不能是INF,我是这么理解的,如果枚举ALL边集显然爆炸,我们可以先跑一遍最短路,记录下最短路上的所有边E,显然删除E之外的边不会影响最短路的长度,所以我们枚举E中的边删除统计最大值。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<functional>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define inf 0x3f3f3f3f
struct Edge{
int u,v,w,next,o;
Edge(){}
Edge(int u,int v,int w,int next,int o):u(u),v(v),w(w),next(next),o(o){}
}e[];
int first[],tot;
void add(int u,int v,int w){
e[tot]=Edge(u,v,w,first[u],);
first[u]=tot++;
}
int n,m;
int d[];
int p[];
bool vis[];
void dij(){
memset(vis,,sizeof(vis));
memset(p,-,sizeof(p));
memset(d,inf,sizeof(d));
d[]=;
priority_queue<pii,vector<pii>,greater<pii> >q;
q.push(mp(,));
while(!q.empty()){
int u=q.top().second;
q.pop();
if(vis[u]) continue;
vis[u]=;
for(int i=first[u];i+;i=e[i].next){
if(e[i].o==-) continue;
if(d[e[i].v]>d[u]+e[i].w){
d[e[i].v]=d[u]+e[i].w;
q.push(mp(d[e[i].v],e[i].v));
p[e[i].v]=i;
}
}
}
}
int main()
{
int i,j,k,ans;
int u,v,w;
while(cin>>n>>m){
memset(first,-,sizeof(first));
tot=;
while(m--){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
dij();
ans=d[n];
int c=n;
while(c!=){
e[p[c]].o=;
c=e[p[c]].u;
}
for(i=;i<tot;++i){
if(e[i].o==){
e[i].o=-;
dij();
if(d[n]==inf) continue;
else{
ans=max(ans,d[n]);
}
e[i].o=;
}
}
cout<<ans<<endl;
}
return ;
}

HDU1595-最短路-删边的更多相关文章

  1. HDU5137-最短路-删点

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  2. Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路 删边

    题目:有n个城镇,m条边权为1的双向边让你破坏最多的道路,使得从s1到t1,从s2到t2的距离分别不超过d1和d2. #include <iostream> #include <cs ...

  3. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  4. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. SGU185 - Two Shortest

    原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=185 题目大意:给出一个无向图,求出从 1 到 n 的两条没有相同边的最短路径(允许 ...

  7. NOIP算法总结

    前言 离NOIP还有一个星期,匆忙的把寒假整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.旁边的同学都劝我不要再放PASCAL啊什么的了,毕竟我们的 ...

  8. 冲刺NOIP复习,算法知识点总结

    前言        离NOIP还有一个星期,匆忙的把整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.当年来学这个竞赛就是为了兴趣,感受计算机之美的. ...

  9. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

随机推荐

  1. web Servlet 3.0 新特性之web模块化编程,web-fragment.xml编写及打jar包

    web Servlet 3.0 模块化 原本一个web应用的任何配置都需要在web.xml中进行,因此会使得web.xml变得很混乱,而且灵活性差,因此Servlet 3.0可以将每个Servlet. ...

  2. 关于ldap的学习

    主要从以下网站学习了相关基础知识概念,安装与基本配置. http://www.aikaiyuan.com/8269.htmlhttps://segmentfault.com/a/11900000026 ...

  3. nginx添加sticky cookie 分流模块

    需要下载nginx源码和sticky,在nginx配置文件中添加sticky模块,然后重新编译nginx. #准备安装基础环境:yum install gcc openssl-devel pcre-d ...

  4. springcloud---2

    每一个都是独立的springboot工程.通过自己的ip和端口访问. Eureka是服务发现组件,Eureka里面有一个服务注册表,存的是服务消费者和服务生产者的ip和端口.Eureka集群里面每个E ...

  5. QML Image Element

    QML Image Element The Image element displays an image in a declarative user interface More... Image元 ...

  6. xshell ssh 上传文件

    一.通过xshell  ssh 上传文件 [lxk@localhost ~]$ yum install lrzsz 安装 [lxk@localhost ~]$ rz 上传文件

  7. mouseover 有一个多次触发的问题

    mouseover 有一个多次触发的问题 需要注意 由于浏览器的冒泡行为.造成如果在一个DIV元素上同时定义了mouseover,mouseout的时候,当鼠标移动到DIV中的child子元素的时候, ...

  8. pom.xml常用元素解析

    project 最外层元素 modelVersion 指定Maven模型的版本号,对于Maven2和Maven3,它只能是4.0.0 version 版本信息 groupId 包id,会生成相应路径 ...

  9. python error: curl: (1) Protocol "'https" not supported or disabled in libcurl

    python 调用curl访问一个网页时,出现error: curl: (1) Protocol "'https" not supported or disabled in lib ...

  10. 20145301《Java程序设计》实验报告一:Java开发环境的熟悉

    20145301<Java程序设计>实验报告一:Java开发环境的熟悉 课程:Java程序设计 实验名称:Java开发环境的熟悉 实验目的与要求: 1.没有Linux基础的同学建议先学习& ...