AC日记——[SDOI2009]晨跑 bzoj 1877
1877: [SDOI2009]晨跑
Time Limit: 4 Sec Memory Limit: 64 MB
Submit: 2131 Solved: 1142
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 1
1 3 1
2 4 1
3 4 1
4 5 1
4 6 1
2 5 5
3 6 6
5 7 1
6 7 1
Sample Output
HINT
对于30%的数据,N ≤ 20,M ≤ 120。
对于100%的数据,N ≤ 200,M ≤ 20000。
Source
#include <cstdio>
#include <iostream> using namespace std; struct EdgeType {
int v,w,f,e;
};
struct EdgeType edge[<<]; int n,m,cnt=,head[<<],que[],dis[<<];
int pre[<<],suc[<<],ans,ans_; bool if_[<<]; char Cget; inline void in(int &now)
{
now=,Cget=getchar();
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(int u,int v,int w,int f)
{
edge[++cnt].v=v,edge[cnt].f=f,edge[cnt].w=w,edge[cnt].e=head[u],head[u]=cnt;
edge[++cnt].v=u,edge[cnt].f=,edge[cnt].w=-w,edge[cnt].e=head[v],head[v]=cnt;
} bool spfa()
{
int h=,tail=;
for(int i=;i<=n*;i++)
{
pre[i]=-;
if_[i]=false;
dis[i]=0x7ffffff;
}
que[tail++]=,dis[]=,if_[]=true;
while(h<tail)
{
for(int i=head[que[h]];i;i=edge[i].e)
{
if(dis[edge[i].v]>dis[que[h]]+edge[i].w&&edge[i].f>)
{
dis[edge[i].v]=dis[que[h]]+edge[i].w;
pre[edge[i].v]=i;
if(!if_[edge[i].v])
{
if_[edge[i].v]=true;
que[tail++]=edge[i].v;
}
}
}
if_[que[h++]]=false;
}
return dis[n+n]<0x7ffffff;
} int main()
{
in(n),in(m);int u,v,w;
edge_add(,+n,,0x7ffffff),edge_add(n,n+n,,0x7ffffff);
for(int i=;i<n;i++) edge_add(i,i+n,,);
for(int i=;i<=m;i++)
{
in(u),in(v),in(w);
edge_add(u+n,v,w,);
}
while(spfa())
{
int pos=n+n,pos_=0x7ffffff;
while(pre[pos]!=-)
{
pos_=min(pos_,edge[pre[pos]].f);
pos=edge[pre[pos]^].v;
}
ans_+=pos_;
pos=n+n;
while(pre[pos]!=-)
{
ans+=edge[pre[pos]].w*pos_;
edge[pre[pos]].f-=pos_;
edge[pre[pos]^].f+=pos_;
pos=edge[pre[pos]^].v;
}
}
cout<<ans_<<' '<<ans;
return ;
}
AC日记——[SDOI2009]晨跑 bzoj 1877的更多相关文章
- BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑
我由衷地为我的朋友高兴.哈哈,yian,当你nick name破百上千时,再打“蒟蒻”就会被打的. 好的,说正事吧.请注意,这还是题解.但我发现,网络流实在是太套路了(怪不得这两年几乎销声匿迹).我们 ...
- BZOJ 1877: [SDOI2009]晨跑 费用流
1877: [SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一 ...
- BZOJ 1877: [SDOI2009]晨跑( 最小费用最大流 )
裸的费用流...拆点, 流量限制为1, 最后的流量和费用即答案. ------------------------------------------------------------------- ...
- 1877: [SDOI2009]晨跑
1877: [SDOI2009]晨跑 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 2007 Solved: 1085[Submit][Status][ ...
- bzoj1877: [SDOI2009]晨跑
挺裸的最小费用最大流... #include<cstdio> #include<queue> #include<cstring> #include<iostr ...
- BZOJ_1877_[SDOI2009]晨跑_费用流
BZOJ_1877_[SDOI2009]晨跑_费用流 题意: Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他 坚持下来的只有晨跑. 现在给出 ...
- 【BZOJ1877】[SDOI2009]晨跑 最小费用最大流
[BZOJ1877][SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现 ...
- [SDOI2009]晨跑[最小费用最大流]
[SDOI2009]晨跑 最小费用最大流的板子题吧 令 \(i'=i+n\) \(i -> i'\) 建一条流量为1费用为0的边这样就不会对答案有贡献 其次是对 \(m\) 条边建 \(u'-& ...
- 【BZOJ】1877: [SDOI2009]晨跑(最小费用最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1877 费用流做多了,此题就是一眼题. 拆点表示只能经过一次,容量为1,费用为0. 然后再连边即可,跑 ...
随机推荐
- python_108_格式化字符串format函数
#通过关键字映射 print('I am {name},age {age}'.format(name='qiqi齐',age=18))#I am qiqi齐,age 18 dictory={'name ...
- python常用模块之requests
一.requests 1.GET url带参数请求 >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> ...
- BestCoder Round#15 1001-Love
http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others) Memory ...
- shell脚本,计算从0+2+4+6+....100的结果是多少?
[root@localhost wyb]# cat evenjia.sh #!/bin/bash #从0++++...100的结果 i= ` do sum=$(($sum+i)) i=$(($i+)) ...
- 设置tableview的滚动范围--iOS开发系列---项目中成长的知识三
设置tableview的滚动范围 有时候tableview的footerview上的内容需要向上拖动界面一定距离才能够看见, 项目中因为我需要在footerviw上添加一个按钮,而这个按钮又因为这个原 ...
- iOS 面试集锦
是第一篇: 1.Difference between shallow copy and deep copy? 浅复制和深复制的区别? 答案:浅层复制:只复制指向对象的指针,而不复制引用对象本身. 深层 ...
- ECMAScript5 [].reduce()
ECMAScript 5 的2个归并数组的方法,reduce() reduceRight() 两个方法都会迭代数组的所有项,然后构建一个最终返回的值. 两个参数: 1.函数,一个在每一项上调用的函 ...
- 118. Pascal's Triangle@python
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. Example: Inpu ...
- ExtJs如何使用自定义插件动态保存表头配置(隐藏或显示)
关于保存列表表头的配置,一般我们不需要与后台交互,直接保存在 localStorage 中就能满足常规使用需求(需要浏览器支持). 直接上代码,插件: Ext.define('ux.plugin.Co ...
- centos7系统优化
优化说明: 一.关闭selinux 二.更改为阿里yum源 三.提权dm用户可以使用sudo 四.优化ssh远程登录配置 五.设置中文字符集 六.设置时间同步 七.历史记录数及登录超时环境变量设置 八 ...