传送门啦

先跑一遍最短路,将最短路的路径记录下来,然后枚举每一条最短路的边,将其断掉,记录此时的1-n的时间,取其中最大的一个时间即为所求。

(通过 $ cut[][] $ 和 $ f[] $ 进行操作)

注意这个题是个稠密图,可能会卡 $ spfa $ ,所以我用了堆优化 $ dijk $ 。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1005;
const int maxm = 500005; inline int read(){char ch = getchar();int f = 1 , x = 0;while(ch > '9' || ch < '0'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + ch - '0';ch = getchar();}return x * f;} int n,m,u,v,w;
int head[maxn],tot;
int dis[maxn],f[maxn],ans;
bool flag,cut[maxn][maxn]; struct Edge{
int from,to,next,val;
}edge[maxm << 1]; struct Node{
int u,d;
bool operator < (const Node &f) const {
return d > f.d;
}
} ; void add(int u,int v,int w){
edge[++tot].from = u;
edge[tot].to = v;
edge[tot].val = w;
edge[tot].next = head[u];
head[u] = tot;
} void dijk(int s){
for(int i=1;i<=n;i++) dis[i] = 1e9;
priority_queue<Node> q;
dis[s] = 0;
q.push( (Node) {s , 0} );
while(!q.empty()){
Node cur = q.top();
q.pop();
int u = cur.u , d = cur.d;
if(d != dis[u]) continue;
for(int i=head[u];i;i=edge[i].next){
int v = edge[i].to;
if(dis[v] > dis[u] + edge[i].val && cut[u][v] == 0){
if(!flag) f[v] = u;
dis[v] = dis[u] + edge[i].val;
q.push((Node) {v , dis[v]});
}
}
}
} int main(){
n = read(); m = read();
for(int i=1;i<=m;i++){
u = read(); v = read(); w = read();
add(u , v , w);
add(v , u , w);
}
dijk(1);
flag = 1;
for(int i=n;i!=1;i=f[i]){
cut[f[i]][i] = 1;
cut[i][f[i]] = 1;
dijk(1);
cut[f[i]][i] = 0;
cut[i][f[i]] = 0;
ans = max(ans , dis[n]);
}
printf("%d\n",ans);
return 0;
}

最新文章

  1. PHPMailer &lt; 5.2.18 - RCE EXP(Bash)
  2. 在 Linux 下将 PNG 和 JPG 批量互转的四种方法
  3. 超级详细的iptable教程文档
  4. service(启动方式)
  5. 0422 Step2-FCFS调度
  6. VS快速格式化代码
  7. SQL语句最基本的性能优化方法
  8. 用NSData和NSFileManager保存内存中的对象
  9. PL/SQL学习(六)触发器
  10. awk 多分隔符
  11. 《Programming WPF》翻译 第8章 1.动画基础
  12. AspNetCore-MVC实战系列(二)之通过绑定邮箱找回密码
  13. redis的主从复制
  14. sublime中css输入分号后自动提示的烦恼
  15. 深入理解Postgres中的cache
  16. bzoj 4605: 崂山白花蛇草水
  17. python selenium+phantomjs alert()弹窗报错
  18. 打开MCMC(马尔科夫蒙特卡洛)的黑盒子 - Pymc贝叶斯推理底层实现原理初探
  19. JavaScript 的 this 原理
  20. SQL Server数据库的兼容级别

热门文章

  1. 解题:POI 2008 Plot purchase
  2. 特征降维之PCA
  3. P3007 [USACO11JAN]大陆议会The Continental Cowngress
  4. charles抓包详解http 与 https
  5. Redis学习三:Redis数据类型
  6. Mongodb开启远程连接并认证
  7. 59、synchronized同步代码块
  8. halcon发布
  9. 記一次undo問題
  10. python进阶之类常用魔法方法和魔法属性