zoukankan      html  css  js  c++  java
  • hdu 3549 Flow problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549

    题意分析:最大网络流 模板题

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<iostream>
    #include<queue>
    #include<algorithm>
    
    #define INF 0x7fffffff
    #define N 100
    
    using namespace std;
    
    int map[N][N],v[N];
    int pre[N];
    int n,m;
    
    int BFS(int s,int t)
    {
        queue<int>q;
        memset(pre,-1,sizeof(pre));
        memset(v,0,sizeof(v));
        pre[s] = s;
        v[s] = 1;
        q.push(s);
        int i;
        while(!q.empty())
        {
            int w = q.front();
            q.pop();
            for(i=1;i<=n;i++)
            {
                if(map[w][i]&&v[i] == 0)
                {
                    pre[i] = w;
                    v[i] = 1;
                    if(i == t)
                    {
                        return 1;
                    }
                    q.push(i);
                }
            }
        }
        return 0;
    }
    
    int EK(int s,int t)
    {
        int count = 0;
        int i,pp;
        while(BFS(s,t))
        {
            pp = INF;
            for(i=t;i!=s;i = pre[i])
            {
                if(pp>=map[pre[i]][i])
                {
                    pp = map[pre[i]][i];
                }
            }
            for(i=t;i!=s;i=pre[i])
            {
                map[pre[i]][i] -= pp;
                map[i][pre[i]] += pp;
            }
            count += pp;
        }
        return count;
    }
    
    int main()
    {
        int T,t=0,i,j;
        scanf("%d",&T);
        while(T--)
        {
            t++;
            int x,y,z;
            scanf("%d%d",&n,&m);
            memset(map,0,sizeof(map));
            while(m--)
            {
                scanf("%d%d%d",&x,&y,&z);
                map[x][y] += z;
            }
            printf("Case %d: %d
    ",t,EK(1,n));
        }
        return 0;
    }
  • 相关阅读:
    mac 命令大全
    GAME OF THRONES 2
    GAME OF THRONES 1
    软件工程-作业一
    猜数字游戏
    摘自-角田光代《对岸的她》
    java复习总结
    艾米莉-狄金森
    初次接触软件工程
    Environment/reflection mapping & bump mapping
  • 原文地址:https://www.cnblogs.com/ACFLOOD/p/4302859.html
Copyright © 2011-2022 走看看