BZOJ 3445: [Usaco2014 Feb] Roadblock
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的更多相关文章
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...
- [Usaco2014 Feb] Roadblock
有一个无向图,共N个节点,编号1至N,共M条边.FJ在节点1,它想到达节点N.FJ总是会选择最短路径到达节点N .作为捣蛋的奶牛Bessie,它想尽量延迟FJ到达节点N的时间,于是Bessie决定从M ...
- [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游
[bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...
- 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 ...
- bzoj3446[Usaco2014 Feb]Cow Decathlon*
bzoj3446[Usaco2014 Feb]Cow Decathlon 题意: FJ有n头奶牛.FJ提供n种不同的技能供奶牛们学习,每头奶牛只能学习一门技能,每门技能都要有奶牛学习. 第i头奶牛学习 ...
- 【BZOJ 3445】【Usaco2014 Feb】Roadblock
http://www.lydsy.com/JudgeOnline/problem.php?id=3445 加倍的边一定在最短路上(否则继续走最短路). 最短路长度是O(n)的,暴力扫最短路上的每条边, ...
- [ BZOJ 3445 ] Roadblock
\(\\\) \(Description\) 给出一张\(N\) 个点\(M\)条边的无向图,选择一条边使其权值翻倍,求操作后比操作前最短路长度增量最大值. \(1\le N\le 250\),\(1 ...
- BZOJ 3940: [Usaco2015 Feb]Censoring
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 367 Solved: 173[Subm ...
- Bzoj 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 二分
1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1272 Solve ...
随机推荐
- git 推送
echo "# shops" >> README.md git init git add README.md git commit -m "first com ...
- 自然语言19_Lemmatisation
QQ:231469242 欢迎喜欢nltk朋友交流 https://en.wikipedia.org/wiki/Lemmatisation Lemmatisation (or lemmatizatio ...
- Java数据库——JDBC 2.0操作
可滚动的结果集 让结果集滚动起来 //================================================= // File Name : JDBC20_demo //-- ...
- C++学习之Pair
C++学习之Pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型, ...
- TeXmacs - 所见即所得 - 专业排版软件
所见即所得,支持中文,很好用, 容易奔溃,奔溃进入不了程序时,删除文件夹 C:\Users\Perelman\AppData\Roaming\TeXmacs
- cmake 静态调用 c++ dll 的类的一个例子(Clion IDE)
CMakeLists.txt project(aaa) add_library(aaa SHARED aaa.cpp) add_executable(bbb bbb.cpp) target_link_ ...
- __cdecl和__stdcall
MSVC在编译C/C++程序的时候,默认采用__cdecl调用约定来编译.__stdcall是Win32 API函数的默认调用规约. Calling Convention Internal* MSVC ...
- live555编译、移植
1.windows下编译 转 http://www.cnblogs.com/skyseraph/archive/2012/04/11/2442840.html 2.linux下编译,以及交叉编译,海思 ...
- SpringMVC -rest风格修改删除
REST风格
- mysql存储过程之异常处理篇
mysql存储过程也提供了对异常处理的功能:通过定义HANDLER来完成异常声明的实现 语法如下: DECLARE handler_type HANDLER FOR condition_value[, ...