【题意概述】

  修改图中任一一条边的边权,使其加倍,问怎样使修改后图中的1~n的最短路最大。输出最短路的增量。

【题解】

  先跑一遍dijkstra求出1~n的路径长度,记录下经过的边。枚举这些边进行修改,再跑dijkstra求出某条边修改后的最短路径的长度。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 200010
#define rg register
using namespace std;
int n,m,tot,ans0,ans1,fa,son,cnt,last[N],pos[N],dis[N],fp[N],fe[N],st[N];
struct edge{int to,pre,d;}e[N];
struct heap{int poi,d;}h[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline void up(int x){
while((fa=(x>>))>&&h[fa].d>h[x].d)
swap(h[fa],h[x]),swap(pos[h[fa].poi],pos[h[x].poi]),x=fa;
}
inline void down(int x){
while((son=(x<<))<=tot){
if(h[son+].d<h[son].d&&son<tot) son++;
if(h[son].d<h[x].d) swap(h[son],h[x]),swap(pos[h[x].poi],pos[h[son].poi]),x=son;
else break;
}
}
inline void dijkstra(int x){
for(rg int i=;i<=n;i++) dis[i]=1e9,pos[i]=;
h[tot=pos[x]=]=(heap){x,dis[x]=};
while(tot){
int now=h[].poi; pos[h[tot].poi]=; h[]=h[tot--]; if(tot) down();
for(rg int i=last[now],to;i;i=e[i].pre)if(dis[to=e[i].to]>dis[now]+e[i].d){
dis[to]=dis[now]+e[i].d; fp[to]=now; fe[to]=i;
if(!pos[to]) h[pos[to]=++tot]=(heap){to,dis[to]};
else h[pos[to]].d=dis[to];
up(pos[to]);
}
}
}
int main(){
n=read(); m=read();
for(rg int i=;i<=m;i++){
int u=read(),v=read(),d=read();
e[++tot]=(edge){v,last[u],d}; last[u]=tot;
e[++tot]=(edge){u,last[v],d}; last[v]=tot;
}
dijkstra();
ans0=dis[n];
int now=n;
while(fp[now]){
st[++cnt]=fe[now];
// printf("now=%d\n",now);
now=fp[now];
}
// for(rg int i=1;i<=cnt;i++) printf("%d ",st[i]);
for(rg int i=;i<=cnt;i++){
int ed=st[i];
if(ed&) e[ed].d<<=, e[ed+].d<<=;
else e[ed].d<<=, e[ed-].d<<=;
dijkstra();
if(ed&) e[ed].d>>=, e[ed+].d>>=;
else e[ed].d>>=, e[ed-].d>>=;
ans1=max(ans1,dis[n]);
// printf("dis=%d\n",dis[n]);
}
printf("%d\n",ans1-ans0);
return ;
}

洛谷 2176 [USACO14FEB]路障Roadblock的更多相关文章

  1. 洛谷——P2176 [USACO14FEB]路障Roadblock

    P2176 [USACO14FEB]路障Roadblock 题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 ...

  2. 洛谷—— P2176 [USACO14FEB]路障Roadblock

    https://www.luogu.org/problem/show?pid=2176 题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一 ...

  3. 洛谷 P2176 [USACO14FEB]路障Roadblock

    题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 号田,牛棚在 N 号田.没有两块田被多条道路连接,以适当的路 ...

  4. [USACO14FEB]路障Roadblock

    题目:洛谷P2176. 题目大意:有n个点m条无向边,一个人要从1走到n,他会走最短路.现在可以让一条边的长度翻倍,求翻倍后这个人要多走多少距离. 解题思路:首先可以知道,翻倍肯定是在最短路上的某条边 ...

  5. 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 解题报告

    P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...

  6. 洛谷P3102 [USACO14FEB]秘密代码Secret Code

    P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...

  7. 洛谷——P2865 [USACO06NOV]路障Roadblocks

    P2865 [USACO06NOV]路障Roadblocks 题目描述 Bessie has moved to a small farm and sometimes enjoys returning ...

  8. 洛谷 P2237 [USACO14FEB]自动完成Auto-complete

    P2237 [USACO14FEB]自动完成Auto-complete 题目描述 Bessie the cow has a new cell phone and enjoys sending text ...

  9. 洛谷 P3102 [USACO14FEB]秘密代码Secret Code

    P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...

随机推荐

  1. 观光公交 2011年NOIP全国联赛提高组(贪心,递推)

    观光公交 2011年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold       题目描述 Description 风景迷人的小城 Y 市 ...

  2. [Swift通天遁地]一、超级工具-(18)创建强大、灵活的日期时间拾取器

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. SAP基本搜索帮助及增强出口

    se11创建基本搜索帮助时,各个参数的含意 选择方法   指定命中列表的数据来源,可以是数据库表,视图,CDS.如果指定了搜索帮助出口函数则该字段可以不输,数据来源可以在出口中自行指定 对话类型: 输 ...

  4. (博弈论)51NOD 1066 Bash游戏

    有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N和K,问最后谁能赢得比赛. 例如N = 3 ...

  5. c++自动导出lua绑定

    cocos 使用bindings-generator脚本代替了toLua++. 编写效率大大提高. 具体的在本机中分享:http://note.youdao.com/noteshare?id=0f41 ...

  6. [ NOI 2001 ] 方程的解数

    \(\\\) \(Description\) 已知一个 \(N\) 元高次方程: \[ k_1x_1^{p_1}+k_2x_2^{p_2}+...+k_nx_n^{p_n}=0 \] 要求所有的 \( ...

  7. [Windows Server 2012] 初识Windows Server 2012

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:初次见识Win ...

  8. 使用openssl搭建CA并颁发服务器证书

    本来整理了一份执行脚本,但是没有找到附件功能.只好直接贴当时自己看过的链接了. 文章标题:Openssl Certificate Authority 转载链接:https://jamielinux.c ...

  9. POJ_2828_Buy Tickets

    题意:插队问题: 2016.5.20,复习这道题. 总结:线段树基础不牢,建树,更新尚不熟悉,注意加强理解记忆. 主要理解:(单点更新,逆序插入) 发生插队时,前面的队伍是连续没有空位的,即pos:2 ...

  10. swift Enumerations

    swift Enumerations enum.case.switch CaseIterable allCases 要区别枚举变量和关联值 枚举变量参与枚举运算: 关联值和rawvalue不参与. A ...