Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个代码

Posted by speedcell4 at 2011-11-14 00:13:48 on Problem 1273
#include<iostream>

using namespace std;

const int MAXN = 400;
const int MAXE = 40000;

bool vis[MAXN];
int n,m,u,v,w,map[MAXN][MAXN],Q[MAXE],path[MAXN];

bool BFS(int src,int des)
{
    Q[0]=src;
    memset(path,0,sizeof(path));
    memset(vis,false,sizeof(vis)); vis[src]=true;
    for(int f=0,r=1,u;f<r;)
    {
        u=Q[f++];
        for(int v=0;n-v>0;v++)
        {
            if(!vis[v]&&map[u][v])
            {
                path[v]=u;
                vis[Q[r++]=v]=true;
                if(v==des) return true;
            }
        }
    }
    return false;
}
int Edmonds_Karp(int src,int des)
{
    int cnt=0,Min;
    while(BFS(src,des))
    {
        Min=0x7fffffff;
        for(int i=des;i!=src;i=path[i]) Min=min(Min,map[path[i]][i]);
        for(int i=des;i!=src;i=path[i]) map[path[i]][i]-=Min,map[i][path[i]]+=Min;
        cnt+=Min;
    }
    return cnt;
}
int main()
{
    while(scanf("%d %d",&m,&n)!=EOF)
    {
        memset(map,0,sizeof(map));
        for(int i=0;m-i>0;i++)
        {
            scanf("%d %d %d",&u,&v,&w);
            map[u-1][v-1]+=w;
        }
        printf("%d\n",Edmonds_Karp(0,n-1));
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator