明显拆点费用流;

type
arr=record
toward,next,cap,cost:longint;
end; const
mm=<<;
maxn=;
maxm=; var
edge:array[..maxm]of arr;
first,slack,d:array[..maxn]of longint;
chose:array[..maxn]of boolean;
s,t,n,m,tot,esum,maxflow,maxcost:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(i,j,k,l:longint);
begin
inc(esum);
edge[esum].toward:=j;
edge[esum].next:=first[i];
first[i]:=esum;
edge[esum].cap:=k;
edge[esum].cost:=l;
end; procedure addedge(i,j,k,l:longint);
begin
add(i,j,k,l);
add(j,i,,-l);
end; function aug(x,flow:longint):longint;
var
now,more,i,too,value:longint;
begin
if x=t then begin
inc(maxflow,flow);
inc(maxcost,flow*d[s]);
exit(flow);
end;
now:=;
chose[x]:=true;
i:=first[x];
while i>= do begin
too:=edge[i].toward;
value:=edge[i].cost;
if (edge[i].cap>) and (not chose[too]) then
if d[x]=d[too]+value then begin
more:=aug(too,min(edge[i].cap,flow-now));
dec(edge[i].cap,more);
inc(edge[i xor ].cap,more);
inc(now,more);
if flow=now then exit(flow);
end
else
slack[too]:=min(slack[too],d[too]+value-d[x]);
i:=edge[i].next;
end;
exit(now);
end; function rel:boolean;
var
i,spent:longint;
begin
spent:=maxlongint;
for i:= to tot do
if not chose[i] then spent:=min(spent,slack[i]);
if spent>=mm then exit(false);
for i:= to tot do
if chose[i] then inc(d[i],spent);
exit(true);
end; procedure into;
var
i,j,k,l:longint;
begin
esum:=-;
fillchar(first,sizeof(first),);
readln(n,m);
s:=;
t:=n<<;
tot:=t;
for i:= to n- do
addedge(i<<-,i<<,,);
addedge(,,maxlongint,);
addedge(n<<-,n<<,maxlongint,);
for i:= to m do begin
readln(j,k,l);
addedge(j<<,k<<-,,l);
end;
fillchar(d,sizeof(d),);
end; begin
into;
maxcost:=;
maxflow:=;
repeat
fillchar(slack,sizeof(slack),$7f);
repeat
fillchar(chose,sizeof(chose),false);
until aug(s,maxlongint)<=;
until not rel;
writeln(maxflow,' ',maxcost);
end.

bzoj 1877: [SDOI2009]晨跑 (网络流)的更多相关文章

  1. BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑

    我由衷地为我的朋友高兴.哈哈,yian,当你nick name破百上千时,再打“蒟蒻”就会被打的. 好的,说正事吧.请注意,这还是题解.但我发现,网络流实在是太套路了(怪不得这两年几乎销声匿迹).我们 ...

  2. BZOJ 1877: [SDOI2009]晨跑 费用流

    1877: [SDOI2009]晨跑 Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一 ...

  3. BZOJ 1877: [SDOI2009]晨跑( 最小费用最大流 )

    裸的费用流...拆点, 流量限制为1, 最后的流量和费用即答案. ------------------------------------------------------------------- ...

  4. bzoj 1877 [SDOI2009]晨跑(最小费用最大流)

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...

  5. BZOJ 1877 [SDOI2009]晨跑(多条不交叉最短路)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1877 [题目大意] 找出最多有几条点不重复的从1到N的路,并且要求在满足这个条件的情况 ...

  6. bzoj 1877: [SDOI2009]晨跑

    #include<cstdio> #include<iostream> #include<cstring> #define M 6009 #define inf 2 ...

  7. BZOJ 1877: [SDOI2009]晨跑(费用流)

    看到要求两个量就下意识的想到了费用流= =,先把一个点拆成两个点就能够解决一个的只经过一次的限制 CODE: #include<cstdio>#include<iostream> ...

  8. 1877: [SDOI2009]晨跑

    1877: [SDOI2009]晨跑 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 2007  Solved: 1085[Submit][Status][ ...

  9. 【BZOJ】1877: [SDOI2009]晨跑(最小费用最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1877 费用流做多了,此题就是一眼题. 拆点表示只能经过一次,容量为1,费用为0. 然后再连边即可,跑 ...

随机推荐

  1. 数据爬取后台(PHP+Python)联合作战

    一. 项目声明 本项目从前端,到后台,以及分布式数据抓取,乃我一个人所写,因此项目并不太完善!在语义分析以及数据处理上并不能尽如意.但是极大的减轻了编辑的工作量! 二. 项目所用技术 本项目中前端采用 ...

  2. 算法------------数组----------------两个数组的交集 II

    给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...

  3. 四、新时间日期API

    一.使用 LocalDate .LocalTime .LocalDateTime LocalDate.LocalTime.LocalDateTime 类的实例是不可变的对象,分别表示使用 ISO-86 ...

  4. cf#516A. Make a triangle!(三角形)

    http://codeforces.com/contest/1064/problem/A 题意:给出三角形的三条边,问要让他组成三角形需要增加多少长度 题解:规律:如果给出的三条边不能组成三角形,那答 ...

  5. html div内第二行文字显示不下的时候才用省略号代替 css实现

    有时候文字太多,但为了美观想要在第二行的时候才显示省略号,而不是第一行超出马上就出现省略号 下面是css代码: overflow:hidden;text-overflow: ellipsis;//显示 ...

  6. Error -26377: No match found for the requested parameter

    Error -26377: No match found for the requested parameter

  7. wpf基础使用_修改窗体图标

    废话不多说,直接开始修改图标步骤: 当然直接使用绝对路径添加图标也是可以的,这种方式不可取,一旦图标移动位置或被删除,就会导致找不到图标文件报错,这里我们介绍的是另一个方式,使用资源文件的方式添加 1 ...

  8. Spring ApplicationContext 简介

    ApplicationContext是对BeanFactory的扩展,实现BeanFactory的所有功能,并添加了事件传播,国际化,资源文件处理等.   configure locations:(C ...

  9. Android开发-API指南-<receiver>

    <receiver> 英文原文:http://developer.android.com/guide/topics/manifest/receiver-element.html 采集(更新 ...

  10. Python入门(4)

    一.while循环 有时候,你可能需要计算机来帮重复做一件事,这时就需要循环. while condition: statements (else: statements ) 当condition条件 ...