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. 然后再连边即可,跑 ...
随机推荐
- 关于CSS3三角的实现
1,向上的三角 ;; ;; </html> 3,向左的三角 ;; </html> 4,向右的三角 ;; ...
- go语音实战读后感——一
1.第一个go程序: package main import ( "fmt" ) func main() { fmt.Println("Hello go") } ...
- fclose - 关闭流
SYNOPSIS 总览 #include <stdio.h> int fclose(FILE *stream); DESCRIPTION 描述 函数 fclose 将名为 stream 的 ...
- BXS入门赛部分writeup
pwn1 盲打(笑) 前言:没有听鱼哥的话,事先没有装好环境,于是开始没做出来,然后全程在装pwntools,经过一番努力,失败了0.0 最终在网上搜了一段python socket连接脚本,终于可 ...
- jquery操作滚动条滚动到指定元素位置 scrollTop
$('.brand_t a').bind('click',function(){ if($(this).attr('title1')){ var toChar = $(this).attr('titl ...
- Bootstrap历练实例:基本按钮群组
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- window nodejs 版本管理器 nvm-windows 教程
先去https://github.com/coreybutler/nvm-windows/releases 下载nvm-setup.zip 安装 安装的过程中会提示是否获取nodejs的管理权限,点确 ...
- perl学习之子例程
1.system function && user function system fucntion:chomp reverse print... user function: & ...
- Django 模版语法 三
使用自定义simple_tag 在 app01 下面创建 templatetags 文件夹,在创建 my_tag.py 文件,内容如下: from django import template fro ...
- NSArray 排序
先研究一种方法 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:]; ; i < ; i++) { ; [arr ...