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 ...
随机推荐
- N-Gram
N-Gram是大词汇连续语音识别中常用的一种语言模型,对中文而言,我们称之为汉语语言模型(CLM, Chinese Language Model). 中文名 汉语语言模型 外文名 N-Gram 定 ...
- 9月23日JavaScript作业----子菜单下拉
例题一.子菜单下拉 <style type="text/css"> *{ margin:0px auto; padding:0px} #menu{ width:700p ...
- 使用github和hexo搭建博客
title: How to build your blog by Hexo in github Welcome to huihuang's blog,you will find what you ex ...
- php json_decode
php代码 <?php $data='[{"Name":"a1","Number":"123","Con ...
- yourphp超出20记录自动删除
$m = M('service_loginlog'); $res =$m->where('card_id='.$_SESSION['card_id'])->order('time desc ...
- 表达式拼接Expression<Func<IEntityMapper, bool>> predicate
/// <summary> /// 重写以筛选出当前上下文的实体映射信息 /// </summary> protected override IEnumerable<IE ...
- 从Microsoft.AspNet.Identity看微软推荐的一种MVC的分层架构
Microsoft.AspNet.Identity简介 Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的mem ...
- 关于Hash集合以及Java中的内存泄漏
<学习笔记>关于Hash集合以及Java中的内存泄漏 标签: 学习笔记内存泄露hash 2015-10-11 21:26 58人阅读 评论(0) 收藏 举报 分类: 学习笔记(5) 版 ...
- Python Web Crawler
Python版本:3.5.2 pycharm URL Parsing¶ https://docs.python.org/3.5/library/urllib.parse.html?highlight= ...
- dom.style.left 与 dom.offsetLeft区别
dom.style.left 初始空值,必须在html行内样式定义值才有值,在css样式定义仍为空值 可读写,是字符串,读写是必须加px,否则无效 ...