Description

一个图, \(n\) 个点 \(m\) 条边,求将一条边距离翻倍后使 \(1-n\) 最短路径增加的最大增量.

Sol

Dijstra.

先跑一边最短路,然后枚举最短路,将路径翻倍然后跑Dijstra...

因为不在最短路径上的边没用贡献,然后最短路径最长为 \(n-1\)

复杂度 \(O(nmlogm\)

Code

/**************************************************************
Problem: 3445
User: BeiYu
Language: C++
Result: Accepted
Time:32 ms
Memory:3332 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
#include <queue>
#include <functional>
#include <iostream>
using namespace std; typedef long long LL;
typedef pair< LL,int > pr;
#define mpr make_pair
const int N = 255; int n,m,cnt;
int b[N],p[N];
LL ans,disn;
LL d[N];
struct Edge{ int fr,to;LL w; }edge[N*N*2];
vector< int > g[N];
priority_queue< pr,vector< pr >,greater< pr > > q;
vector< int > path; inline int in(int x=0){ scanf("%d",&x);return x; }
void Add_Edge(int fr,int to,int w){
edge[++cnt]=(Edge){ fr,to,w };
g[fr].push_back(cnt);
}
void GetPath(){
for(int x=n;x!=1;x=edge[p[x]].fr) path.push_back(p[x]);
}
void Dijstra(int s,int fst){
memset(b,0,sizeof(b));
memset(d,0x3f,sizeof(d));
d[s]=0,q.push(mpr(0LL,s));
for(int x;!q.empty();){
x=q.top().second,q.pop();if(b[x]) continue;b[x]=1;
for(int i=0,lim=g[x].size();i<lim;i++){
int v=edge[g[x][i]].to;LL w=edge[g[x][i]].w;
// cout<<x<<" "<<v<<" "<<w<<" "<<d[x]<<" "<<d[v]<<endl;
if(d[x]+w < d[v]){
d[v]=d[x]+w,p[v]=g[x][i];
q.push(mpr(d[v],v));
}
}
}
// cout<<d[n]<<endl;
if(fst) disn=d[n],GetPath();
else ans=max(ans,d[n]-disn);
}
int main(){
n=in(),m=in();
for(int i=1,u,v,w;i<=m;i++) u=in(),v=in(),w=in(),Add_Edge(u,v,w),Add_Edge(v,u,w);
Dijstra(1,1); // for(int i=0,lim=path.size();i<lim;i++) cout<<edge[path[i]].fr<<" "<<edge[path[i]].to<<" "<<edge[path[i]].w<<endl; for(int i=0,lim=path.size();i<lim;i++) edge[path[i]].w*=2,Dijstra(1,0),edge[path[i]].w/=2;
cout<<ans<<endl;
return 0;
}

  

BZOJ 3445: [Usaco2014 Feb] Roadblock的更多相关文章

  1. BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

    水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...

  2. [Usaco2014 Feb] Roadblock

    有一个无向图,共N个节点,编号1至N,共M条边.FJ在节点1,它想到达节点N.FJ总是会选择最短路径到达节点N .作为捣蛋的奶牛Bessie,它想尽量延迟FJ到达节点N的时间,于是Bessie决定从M ...

  3. [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游

    [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...

  4. BZOJ_3448_[Usaco2014 Feb]Auto-complete_Trie树

    BZOJ_3448_[Usaco2014 Feb]Auto-complete_Trie Description Bessie the cow has a new cell phone and enjo ...

  5. bzoj3446[Usaco2014 Feb]Cow Decathlon*

    bzoj3446[Usaco2014 Feb]Cow Decathlon 题意: FJ有n头奶牛.FJ提供n种不同的技能供奶牛们学习,每头奶牛只能学习一门技能,每门技能都要有奶牛学习. 第i头奶牛学习 ...

  6. 【BZOJ 3445】【Usaco2014 Feb】Roadblock

    http://www.lydsy.com/JudgeOnline/problem.php?id=3445 加倍的边一定在最短路上(否则继续走最短路). 最短路长度是O(n)的,暴力扫最短路上的每条边, ...

  7. [ BZOJ 3445 ] Roadblock

    \(\\\) \(Description\) 给出一张\(N\) 个点\(M\)条边的无向图,选择一条边使其权值翻倍,求操作后比操作前最短路长度增量最大值. \(1\le N\le 250\),\(1 ...

  8. BZOJ 3940: [Usaco2015 Feb]Censoring

    3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 367  Solved: 173[Subm ...

  9. Bzoj 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 二分

    1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1272  Solve ...

随机推荐

  1. Java数据结构——链表-单链表

    <1>链表 <2>引用和基本类型 <3>单链表 //================================================= // Fil ...

  2. Java排序算法——选择排序

    import java.util.Arrays; //================================================= // File Name : Select_S ...

  3. PHP 出现 502 解决方案

    原文:http://www.ahlinux.com/php/10319.html nginx+php 出现502 bad gateway,一般这都不是nginx的问题,而是由于 fastcgi或者ph ...

  4. My latest news (--2016.10)

    2016.10.31 22:44 一个“程序”,打代码占40%.思考占60% 2016.10.30 20:53 周末,话说今天有晚上讲座,还点名,了,悲催.之前学习的Qt有点问题,悲催.推荐个博文:h ...

  5. Red Black Tree in C

    http://web.mit.edu/~emin/www.old/source_code/red_black_tree/index.html

  6. 安装 SQL server 2008 R2

    操作系统:WIN7 问题: The Windows Installer Service could not be accessed. This can occur if the Windows Ins ...

  7. Mysql InnoDB行锁实现方式(转)

    Mysql InnoDB行锁实现方式 InnoDB行锁是通过给索引上的索引项加锁来实现的,这一点MySQL与Oracle不同,后者是通过在数据块中对相应数据行加锁来实现的.InnoDB这种行锁实现特点 ...

  8. StringUtils

    StringUtils.hasText(字符串) 如果字符串里面的值为null, "", "   ",那么返回值为false:否则为true

  9. 脱离 Spring 实现复杂嵌套事务,之一(必要的概念)

    事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播: 表1事务传播行为类型 事务 ...

  10. Source Insight 基本使用(2)-修改Source Insight 快捷键

    1. 首先,打开source insight主界面. 2. 选择"options->key assignments",进入快捷键设置界面. 3. 此时,可以看到快捷键设置对话 ...