HDU 3549 Flow Problem ( 最大流 -EK 算法)

C++,G++的读取速度差距也太大了

Flow Problem

题意:n,m表示n个点m条有向带权边

问:从1-n最大流多少

裸最大流,拿来练手,挺不错的

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
const int N = 210;
#define MIN INT_MIN
#define MAX INT_MAX
#define LL long long
using namespace std;
int max(int a,int b){if(a>b)return a; else return b;}
int min(int a,int b){if(a<b)return a; else return b;}
int c[100][100];
int re[100];
int f[100][100];
int p[100],n,m;
void init()
{
    for(int i = 0;i<=n;i++)
    {
        for(int j = 0;j<=n;j++)
        {
            c[i][j] = f[i][j] = 0;
        }
        p[i] = 0;
    }
}
void EK(int s,int t)
{
    queue<int >q;
    while(q.empty()==false) q.pop();
    int sum = 0;
    while(1)
    {
        memset(re,0,sizeof(re));
        q.push(s);
        re[s] = MAX;
        p[s] = -1;
        while(!q.empty())
        {
            int u = q.front();
            q.pop();
            for(int i = 1;i<=n;i++)
            {
                if(!re[i] && f[u][i] < c[u][i])
                {
                    q.push(i);
                    p[i] = u;
                    re[i] = min(re[u],c[u][i]-f[u][i]);
                }
            }
        }
        if(re[t]==0) break;
        for(int st = t;st!=s;st = p[st])
        {
            f[p[st]][st] += re[t];
            f[st][p[st]] -= re[t];
        }
        sum += re[t];
    }
    printf("%d\n",sum);
}

int main()
{
    int t,C=0,a,b,w;
    scanf("%d",&t);
    while(t--)
    {
        C++;
        scanf("%d%d",&n,&m);
        init();
        for(int i = 0;i<m;i++)
        {
            scanf("%d%d%d",&a,&b,&w);
            c[a][b] += w;
        }
        printf("Case %d: ",C);
        EK(1,n);
    }
    return 0;
}

HDU 3549 Flow Problem ( 最大流 -EK 算法),布布扣,bubuko.com

时间: 2024-12-24 11:55:49

HDU 3549 Flow Problem ( 最大流 -EK 算法)的相关文章

HDU 3549 Flow Problem 网络最大流问题 Edmonds_Karp算法

题目链接:HDU 3549 Flow Problem Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 8218    Accepted Submission(s): 3824 Problem Description Network flow is a well-known difficult problem f

hdu - 3549 Flow Problem (最大流模板题)

http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <stri

HDU 3549 Flow Problem (最大流)

链接:click here 题意:Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph. 翻译:网络流量是一个众所周知的难题ACMers.给定一个图,你的任务是找出加权有向图的最大流. 输出格式: Case 1: 1 Case 2: 2 思路:跟hdu153

hdu 3549 Flow Problem(最大流模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph. Input The first line of input

hdu 3549 Flow Problem (网络最大流)

Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 6674    Accepted Submission(s): 3112 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, yo

网络流 HDU 3549 Flow Problem

网络流 HDU 3549 Flow Problem 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法进行求解,注意的问题有两个: 1. 每次增广的时候,反向流量也要进行更行,一开始没注意,WA了几次 ORZ 2. 对于输入的数据,容量要进行累加更新. // 邻接矩阵存储 #include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const i

HDU 3549 Flow Problem (用一道最裸的最大流开启网络流算法之路)

Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 9423    Accepted Submission(s): 4405 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, y

HDU 3549 Flow Problem(最大流)

Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 12625    Accepted Submission(s): 6004 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph,

HDU 3549 Flow Problem (最大流ISAP)

Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 8199    Accepted Submission(s): 3814 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, yo