AC日记——[Sdoi2010]星际竞速 bzoj 1927
思路:
连边,拆点;
每个点拆成i,i+n,都向t连边;
i到t表示高速模式,i+n到t表示跳跃模式;
然后读入路径,如果u>v,则交换u,v;
u向v+n连边;
spfa跑最小费用;
来,上代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 805
#define maxm 7000000
#define INF 0x7fffffff int dis[maxn<<],cnt=,s,t,que[maxm],pre[maxn<<],ans;
int n,m,head[maxn<<],E[maxm],V[maxm],F[maxm],W[maxm]; bool if_[maxn<<]; inline void in(int &now)
{
register int if_z=;now=;
register char Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} bool spfa()
{
for(int i=s;i<=t;i++) dis[i]=INF,pre[i]=-,if_[i]=false;
int h=,tail=;dis[s]=,if_[s]=true,que[]=s;
while(h<tail)
{
int now=que[h++];if_[now]=false;
for(int i=head[now];i;i=E[i])
{
if(F[i]>&&dis[V[i]]>dis[now]+W[i])
{
pre[V[i]]=i;
dis[V[i]]=dis[now]+W[i];
if(!if_[V[i]])
{
if_[V[i]]=true;
que[tail++]=V[i];
}
}
}
}
return dis[t]!=INF;
} int main()
{
in(n),in(m);
t=n*+;int u,v,pos;
for(int i=;i<=n;i++)
{
in(pos);
E[++cnt]=head[s],V[cnt]=i,F[cnt]=,W[cnt]=,head[s]=cnt;
E[++cnt]=head[i],V[cnt]=s,F[cnt]=,W[cnt]=,head[i]=cnt;
E[++cnt]=head[s],V[cnt]=i+n,F[cnt]=,W[cnt]=pos,head[s]=cnt;
E[++cnt]=head[i+n],V[cnt]=s,F[cnt]=,W[cnt]=-pos,head[i+n]=cnt;
E[++cnt]=head[i+n],V[cnt]=t,F[cnt]=,W[cnt]=,head[i+n]=cnt;
E[++cnt]=head[t],V[cnt]=i+n,F[cnt]=,W[cnt]=,head[t]=cnt;
}
while(m--)
{
in(u),in(v),in(pos);
if(u>v) swap(u,v);
E[++cnt]=head[u],V[cnt]=v+n,F[cnt]=,W[cnt]=pos,head[u]=cnt;
E[++cnt]=head[v+n],V[cnt]=u,F[cnt]=,W[cnt]=-pos,head[v+n]=cnt;
}
while(spfa())
{
int now=t;pos=INF;
while(pre[now]!=-) pos=min(pos,F[pre[now]]),now=V[pre[now]^];now=t;
while(pre[now]!=-) F[pre[now]]-=pos,F[pre[now]^]+=pos,now=V[pre[now]^];
ans+=pos*dis[t];
}
cout<<ans;
return ;
}
AC日记——[Sdoi2010]星际竞速 bzoj 1927的更多相关文章
- Luogu 2469 [SDOI2010]星际竞速 / HYSBZ 1927 [Sdoi2010]星际竞速 (网络流,最小费用流)
Luogu 2469 [SDOI2010]星际竞速 / HYSBZ 1927 [Sdoi2010]星际竞速 (网络流,最小费用流) Description 10年一度的银河系赛车大赛又要开始了.作为全 ...
- 【bzoj】1927 [Sdoi2010]星际竞速
[算法]最小费用最大流 [题解]跟滑雪略有类似,同样因为可以重复所以不是最小路径覆盖. 连向汇的边容量为1足矣,因为一个点只会出去一次(路径结束). bzoj 1927 [Sdoi2010]星际竞速 ...
- BZOJ 1927: [Sdoi2010]星际竞速
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2051 Solved: 1263[Submit][Stat ...
- BZOJ 1927: [Sdoi2010]星际竞速 费用流
1927: [Sdoi2010]星际竞速 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- bzoj 1927 [Sdoi2010]星际竞速(最小费用最大流)
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1576 Solved: 954[Submit][Statu ...
- BZOJ 1927: [Sdoi2010]星际竞速(最小费用最大流)
拆点,费用流... ----------------------------------------------------------------------------- #include< ...
- BZOJ 1927: [Sdoi2010]星际竞速 [上下界费用流]
1927: [Sdoi2010]星际竞速 题意:一个带权DAG,每个点恰好经过一次,每个点有曲速移动到他的代价,求最小花费 不动脑子直接上上下界费用流过了... s到点连边边权为曲速的代价,一个曲速移 ...
- Bzoj 1927: [Sdoi2010]星际竞速(网络流)
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MB Description 10年一度的银河系赛车大赛又要开始了.作为全银河最盛大 ...
- 1927: [Sdoi2010]星际竞速
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2040 Solved: 1257[Submit][Stat ...
随机推荐
- C++从键盘读入数组并存储
C++从键盘读取任意长度的数组,现总结如下: //读取指定长度的数组 int main() { int n = 0; cin >> n; vector<int> p(n); f ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- 模拟:HDU1034-Candy Sharing Game
解题心得: 1.直接模拟每一次分一半就行了,模拟过程,记录轮数,但是也看到有些大神使用的是链表,估计链表才是真的做法吧. 题目: Candy Sharing Game Time Limit: 2000 ...
- 2018年湘潭大学程序设计竞赛 E 吃货
题目描述 作为一个标准的吃货,mostshy又打算去联建商业街觅食了.混迹于商业街已久,mostshy已经知道了商业街的所有美食与其价格,而且他给每种美食都赋予了一个美味度,美味度越高表示他越喜爱这种 ...
- Android拨打电话不弹出系统拨号界面总结
我在网上搜了一下,解决这个问题,有两种方式: 1.反射调用系统底层方法,并获取系统权限 反射调用的代码如下: Class phoneFactoryClass = Class.forName(" ...
- 设计模式之第0章-单例模式(Java实现)
设计模式之第0章-单例模式(Java实现) 当当当当~首先有请最简单的单例模式登场,先来个自我介绍吧 单例模式之自我介绍 我,单例模式(Singleton Pattern)是一个比较简单的模式,我的定 ...
- leetcode 【 Linked List Cycle II 】 python 实现
公司和学校事情比较多,隔了好几天没刷题,今天继续刷起来. 题目: Given a linked list, return the node where the cycle begins. If the ...
- 【Rotate List】cpp
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...
- 图说不为人知的IT传奇故事-2-IBM咬不动的胡桃
此系列文章为“图说不为人知的IT传奇故事”,各位大忙人可以在一分钟甚至几秒内了解把握整个内容,真可谓“大忙人的福利”呀!!希望各位IT界的朋友在钻研技术的同时,也能在文学.历史上有所把握.了解这些故事 ...
- DFS和BFS遍历的问题
来自https://github.com/soulmachine/leetcode 广度优先搜索 输入数据:没有什么特征,不像dfs需要有递归的性质.如果是树/图,概率更大. 状态转换图:数或者DAG ...