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 |
救命呀,请大虾们帮帮忙!#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<ctype.h> int K,C,M,c[300][300],n,map[300][300],list[300],d[300],pre[300],delta; bool v[300]; void bfs() { int head1=0,tail1=0,x; memset(v,true,sizeof(v)); memset(pre,0,sizeof(pre)); v[0]=list[0]=0; d[0]=99999999; d[n+1]=-1; while(head1<=tail1) { x=list[head1]; for(int i=0;i<=n+1;i++) if(v[i]&&map[x][i]) { list[++tail1]=i; v[i]=false; pre[i]=x; d[i]=d[x]>map[x][i]?map[x][i]:d[x]; } head1++; } delta=d[n+1]; if(delta==-1) return; x=n+1; while(pre[x]!=0) { map[pre[x]][x]-=delta; map[x][pre[x]]+=delta; x=pre[x]; } } int main() { scanf("%d%d%d",&K,&C,&M); n=C+K; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%d",&c[i][j]); if(c[i][j]==0) c[i][j]=99999999; } for(int p=1;p<=n;p++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) c[i][j]=c[i][j]>(c[i][p]+c[p][j])?(c[i][p]+c[p][j]):c[i][j]; int head=0,tail=1000; while(head<tail) { int mid=(head+tail)/2,ans=0; memset(map,0,sizeof(map)); for(int i=K+1;i<=n;i++) map[0][i]=1; for(int i=1;i<=K;i++) map[i][n+1]=M; for(int i=K+1;i<=n;i++) for(int j=1;j<=K;j++) if(c[i][j]<=mid) map[i][j]=1; while(1) { bfs(); if(delta==-1) break; else ans+=delta; } if(ans>=C) tail=mid; else head=mid+1; } printf("%d\n",tail); return 0; } 为什么老是WA Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator