codevs1034
2015-07-18 15:43
405 查看
题目地址:http://codevs.cn/problem/1034/
代码:
代码:
type ss=record y,c,r,next:longint; end; const maxn=10100; maxm=100000; oo=maxlongint shr 2; var n,m,i,j,k,l,st,ed,t1,t2,t,tot,limit,ans,augo:longint; v:array[0..30] of boolean; ee:array[0..30,0..30] of boolean; e:array[0..maxm] of ss; r,z:array[0..31] of longint; p:array[0..31,0..100] of longint; h,g,b,d:array[0..maxn] of longint; can:boolean; procedure shi(k:longint); var i:longint; begin if v[k] then exit; v[k]:=true; for i:=1 to n do if ee[k,i] then shi(i); if v then exit; end; procedure jia(x,y,c:longint); begin inc(tot); e[tot].y:=y; e[tot].c:=c; e[tot].next:=b[x]; b[x]:=tot; inc(tot); e[tot].y:=x; e[tot].next:=b[y]; b[y]:=tot; e[tot].r:=tot-1; e[tot-1].r:=tot; end; procedure flow(k:longint); var i,temp:longint; begin temp:=augo; if k=ed then begin can:=true; inc(ans,augo); exit; end; i:=d[k]; while i<>-1 do begin if e[i].c>0 then begin if h[e[i].y]+1=h[k] then begin if e[i].c<augo then augo:=e[i].c; flow(e[i].y); if h[st]>=limit then exit; if can then break; end; augo:=temp; end; i:=e[i].next; end; if can then begin d[k]:=i; dec(e[i].c,augo); inc(e[e[i].r].c,augo); end else begin d[k]:=b[k]; dec(g[h[k]]); if g[h[k]]<=0 then h[st]:=limit; inc(h[k]); inc(g[h[k]]); end; end; begin readln(n,m,k); for i:=1 to m do begin read(r[i],z[i]); for j:=0 to z[i]-1 do begin read(p[i,j]); if p[i,j]=0 then p[i,j]:=n+1; if p[i,j]=-1 then p[i,j]:=n+2; end; for j:=0 to z[i]-1 do for l:=0 to z[i]-1 do ee[p[i,j],p[i,l]]:=true; end; inc(n,2); shi(n-1); if not(v ) then writeln(0) else begin st:=1000; ed:=1001; fillchar(b,sizeof(b),255); jia(st,n-1,k); jia(n,ed,oo); repeat inc(t); jia(st,n-1+t*n,k); jia(n+t*n,ed,oo); for i:=1 to n do jia(i+(t-1)*n,i+t*n,oo); for i:=1 to m do begin t1:=p[i,(t-1) mod z[i]]+(t-1)*n; t2:=p[i,t mod z[i]]+t*n; jia(t1,t2,r[i]); end; limit:=(t+1)*n+2; fillchar(h,sizeof(h),0); fillchar(g,sizeof(g),0); g[0]:=limit; for i:=1 to limit do d[i]:=b[i]; d[st]:=b[st]; d[ed]:=b[ed]; while h[st]<limit do begin can:=false; augo:=oo; flow(st); end; until ans>=k; writeln(t); end; end.
相关文章推荐
- Web Service -- 使用CXF开发入门
- Java中的五种单例模式实现方法
- 字符串面试题:将字符串转换为整数
- 黑马程序员——Java基础---异常
- C++ string.replace的使用
- C++ string.replace的使用
- 什么叫大数据?什么叫O2O?什么叫蓝海?什么叫红海?什么叫互联网思维?什么叫众筹?
- 九度oj 1054
- 如何设置两个元件靠近后不变绿不报警
- Web Service介绍
- 数据结构--堆排序
- 未来网络的主宰——云操作系统
- 算法导论 第二十一章:不相交集合的数据结构
- Android入门第八篇之GridView(九宫图)
- 如何从string 转换为const char *和char * (附带string中c_str()、data()、copy(p,n)函数的用法)
- X240-win8.1无法连接无线网络的解决方案
- 字符串面试题:将句子的单词序倒置
- ECshop彻底去版权(同时适用于2.7.3)
- ECshop彻底去版权(同时适用于2.7.3)
- java 内存数据的条件筛选和分页处理