Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
wa#include<cstdio> #include<cstdlib> #include<cstring> struct node{int x,y,z; }sa[40200]; int n,p,t; struct node1{int x,y,d,next,other; }sb[80200]; int len,first[400]; int low=2891928,high=0; int sst,eed,h[400],tt[400]; void add(int x,int y,int z) { len++; sb[len].x=x; sb[len].y=y; sb[len].d=z; sb[len].next=first[x]; sb[len].other=len+1; first[x]=len; len++; sb[len].x=y; sb[len].y=x; sb[len].next=first[y]; sb[len].other=len-1; sb[len].d=0; first[y]=len; } bool built() { int st=1,ed=2; tt[st]=sst; memset(h,0,sizeof(h)); h[sst]=1; while(st<ed) { int x=tt[st]; for(int i=first[x];i!=0;i=sb[i].next) { int y=sb[i].y; if(sb[i].d>0&&h[y]==0) { h[y]=h[x]+1; tt[ed]=y; ed++; } } st++; } if(h[eed]>0) return true; return false; } int min(int x,int y) { if(x<y) return x; return y; } int find(int x,int f) { if(x==eed) return f; int s=0,o; for(int i=first[x];i!=0;i=sb[i].next) { int y=sb[i].y; if(sb[i].d>0&&h[y]==h[x]+1&&s<f) { o=find(y,min(sb[i].d,f-s)); s+=o; sb[i].d-=o; sb[sb[i].other].d+=o; } } if(s==0) h[x]=0; return s; } int main() { scanf("%d%d%d",&n,&p,&t); int x,y,z; for(int i=1;i<=p;i++) { scanf("%d%d%d",&x,&y,&z); sa[i].x=x; sa[i].y=y; sa[i].z=z; if(low>z) low=z; if(high<z) high=z; } int mid,l=low,r=high; sst=1; eed=n; // printf("%d %d\n",low,high); int mm=39283333; while(l<r) { mid=(l+r)/2; // printf("%d\n",mid); memset(first,0,sizeof(first)); len=0; for(int i=1;i<=p;i++) { if(mid>=sa[i].z) { add(sa[i].x,sa[i].y,1); } } int ans=0; while(built()==true) { ans+=find(sst,t); } // printf("%d\n",ans); if(ans==t) { r=mid; if(mm>mid) mm=mid; } else l=mid+1; } printf("%d",mm); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator