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进行数据分析1_numpy的基本操作,建模基础
import numpy as np # 生成指定维度的随机多维数据 data=np.random.rand(2,3) print(data) print(type(data)) 结果: [[0.11 ...
- Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameter 标签: 构造器注入Spring
问题:要么是因为构造方法改变了,要么就是构造方法入参实例化失败(比如没有实现) 问题 在练习spring构造器注入方式的小程序的时候报错: Exception in thread “main” org ...
- AR报表控件的常见问题汇总
1)字符串格式不正确 原因是建立报表时未使用分页报表 导致拖动数据为sum()表达式,sum运算字符串当然会出问题 2)超出索引 顾名思义 数据为空或不匹配 3)图片使用远程图片时记得把属性修改为远程 ...
- apache 报413
http://www.hostlift.com/apache/modsecurity-request-body-content-length-is-larger-than-the-configured ...
- nginx目录结构和配置文件
nginx软件功能模块说明 Nginx软件之所以强大,是因为它具有众多的功能模块,下面列出了企业常用的重要模块. (1) Nginx核心功能模块(Core functionality)nginx核心功 ...
- jenkins插件开发(二)
https://wiki.jenkins.io/display/JENKINS/Extend+Jenkins http://commons.apache.org/proper/commons-jell ...
- C/SV/VERILOG语句块界定符不一样
C是一对大括号{} SV /VERILOG 是begin...end
- LeetCode(112) Path Sum
题目 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- 【MySQL】浅谈 varchar(N)
一 前言 varchar(N) N代表什么意思,能存放多少个中文字符?属于老生常谈的问题了,今天又被一个开发同事问我关于这个问题,索性写一篇文章来具体介绍一下.二 理论知识 先说明一下 MySQL ...
- struts2模版搭建
点击MyEclipse菜单栏File按钮,点击new-->Web Project 输入Project name之后点击Finish 项目创建完成. 然后右键项目,点击MyEclipse--> ...