HDU1595-最短路-删边
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
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.
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.
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
13
27
#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-最短路-删边的更多相关文章
- HDU5137-最短路-删点
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路 删边
题目:有n个城镇,m条边权为1的双向边让你破坏最多的道路,使得从s1到t1,从s2到t2的距离分别不超过d1和d2. #include <iostream> #include <cs ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- SGU185 - Two Shortest
原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=185 题目大意:给出一个无向图,求出从 1 到 n 的两条没有相同边的最短路径(允许 ...
- NOIP算法总结
前言 离NOIP还有一个星期,匆忙的把寒假整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.旁边的同学都劝我不要再放PASCAL啊什么的了,毕竟我们的 ...
- 冲刺NOIP复习,算法知识点总结
前言 离NOIP还有一个星期,匆忙的把整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.当年来学这个竞赛就是为了兴趣,感受计算机之美的. ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
随机推荐
- pytorch rnn 2
import torch import torch.nn as nn import numpy as np import torch.optim as optim class RNN(nn.Modul ...
- DataGird 相关
DataGird控件 DataGirdView 控件 DataGird类 他们之间是什么关系??????? DataGridView 控件是替换 DataGrid 控件的新控 ...
- Objective-C中的alloc和init问题
从开始学的NSString *name=[[NSString alloc] init] 起,仅仅这句话是分配内存空间,一直在用,从来没考虑过它的内部是怎么实现的.今天无意中看到了这一句代码: NSSt ...
- vueRouter点击打开新页签
一.vue 路由使用 vue是单页面SPA,一般我们使用vue-router 设定路由进行页面跳转的时候,都是直接覆盖当前页面.比如,在a页面中有如下超链接 <router-link to=&q ...
- Linux系统——源码编译安装
记得要先去把httpd-2.2.9.tar.gz通过xftp进行文件传输第一步:yum仓库下安装编译环境的支持程序 #yum -y install gcc gcc-c++ make 第二步:将源码包h ...
- Springboot 日志管理配置logback-spring.xml
几种常见的日志 Log4j:是最早的日志框架,是apach旗下的,可以单独使用,也可配合日志框架JCL使用: Log4j2:apach旗下的关于log4j的升级版: Logback:是基于slf4j接 ...
- 【android内存泄露】 WebView篇
在咱的博客园app里,新闻的内容使用WebView展示的.在测试中,咱重复进入.退出某个新闻10多次,观察到 Objects一直在不断增长,反复触发GC,但是一直回收不了,占用的内存越来越高,于是警觉 ...
- peeping tom 在渗透信息收集前的作用。
原本想写个截屏类的脚本,发现已经有了这个 py脚本 名字叫作: peeping tom 想要了解详细,戳:https://bitbucket.org/LaNMaSteR53/peepingtom/ ...
- iOS 使用node js 搭建简单的本地服务器
一.前提:基于iOS 项目 调用,使用了第三方框架NodeMobile.技术说明关键是 应用生命整个周期只能在应用启动时候开辟的一个线程里申请 一个 node js 资源.如果终止了运行,重启是不支 ...
- Ubuntu安装dlib后import出现libstdc++.so.6: version `GLIBCXX_3.4.21' not found
1 问题描述 先安装依赖包cmake,libboost,再安装dlib sudo apt-get install cmake sudo apt-get install libboost-python- ...