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 |
神啊!为什么我2个BFS的网络流,都过了USACO 的这个题目?难道不是USACO那个题目么? 谁说说…… /* ID:xueyifa1 LANG:C++ TASK:ditch */ #include<iostream> #include<string.h> #include<queue> using namespace std; int S,T;//源,汇 int a,b; int map[250][250],flow[250][250],just[250]; int vi[250]; void init(){ int i,x,y,z; memset(map,0,sizeof(map)); //原始网络清理掉 memset(vi,0,sizeof(vi)); // 每个点的流量 cin>>a>>b; //读入的,a个路,B是汇 for (i=1;i<=a;i++){ cin>>x>>y>>z; map[x][y]+=z; } S=1;//源 T=b;//汇 } void maxflow(){ int ans,i,j,k; int u,v;//起点,终点 queue<int> q; //队列 memset(flow,0,sizeof(flow)); ans=0; for (;;){ memset(vi,0,sizeof(vi)); //每个点的流量目前是0 vi[S]=20000000; //源为oo的流量 q.push(S); //源进入头结点 while(!q.empty()){ //队列不为空时候,执行循环操作 u=q.front(); q.pop(); //u=队头,队头删除掉 for (v=1;v<=b;v++) if (vi[v]==0 && map[u][v]>flow[u][v]){ //如果,还有可以走的流,0流不给走! just[v]=u;//记录前驱 q.push(v); //v进入队尾 // vi[v]=vi[u] <? map[u][v]-flow[u][v];//取小数字 vi[u]=min(vi[u],map[u][v]-flow[u][v]); vi[v]=vi[u]; } } if (vi[T]==0)break; //找不到,则当前已经得到最大流了,哈哈哈哈哈哈哈! for (u=T;u!=S;u=just[u]){ flow[just[u]][u]+=vi[T]; flow[u][just[u]]-=vi[T]; } ans+=vi[T]; } cout<<ans<<"\n"; } int main(){ // freopen("ditch.in","r",stdin); // freopen("ditch.out","w",stdout); init(); maxflow(); // system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator