zoukankan      html  css  js  c++  java
  • UVA 10330 Power Transmission

    题意:懒得打了。LUCKY CAT 里有 http://163.32.78.26/homework/q10330.htm

    第一个网络流题目。每个节点都有一个容量值。需要拆点。拆成i - > i + N  边权为容量值

    另外注意B个点 连接方式:s - 集合B

    D个点 链接方式 集合D + N -> t汇点

    其他看处理就好

    #include <map>
    #include <set>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define PI 3.1415926535897932626
    using namespace std;
    int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
    #define MAXN 250
    const int INF = 0x3f3f3f3f ;
    int flow[MAXN][MAXN],c[MAXN][MAXN];
    int p[MAXN];
    int N,M,B,D,src,tag;
    void read()
    {
        memset(c,0,sizeof(c));
        src = 0; tag = 2 * N + 1;
        for (int i = 1; i <= N; i++)
        {
            int tmp;
            scanf("%d",&tmp);
            c[i][i + N] = tmp;
        }
        scanf("%d",&M);
        for (int i = 1; i <= M; i++)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            c[u + N][v] = w;
        }
        scanf("%d%d",&B,&D);
        for (int i = 1; i <= B; i++)
        {
            int tmp;
            scanf("%d",&tmp);
            c[0][tmp] = INF;
        }
        for (int i = 1; i <= D; i++)
        {
            int tmp;
            scanf("%d",&tmp);
            c[tmp + N][tag] = INF;
        }
    }
    int Edmonds_karp(int src,int tag)
    {
        memset(flow,0,sizeof(flow));
        int ans = 0;
        queue<int>q;
        while (!q.empty()) q.pop();
        int a[MAXN];
        while (true)
        {
            memset(a,0,sizeof(a));
            a[src] = INF;
            q.push(src);
            while (!q.empty())
            {
                int u = q.front(); q.pop();
                for (int v = 0; v <= tag; v++)
                    if (!a[v] && c[u][v] > flow[u][v])
                {
                    p[v] = u;
                    q.push(v);
                    a[v] = min(a[u],c[u][v] - flow[u][v]);
                }
            }
            if (a[tag] == 0) break;
            for (int u = tag; u != src; u = p[u])
            {
                flow[p[u]][u] += a[tag];
                flow[u][p[u]] -= a[tag];
            }
            ans += a[tag];
        }
        return ans;
    }
    int main()
    {
        //freopen("sample.txt","r",stdin);
        while (scanf("%d",&N)!=EOF)
        {
            read();
            printf("%d
    ",Edmonds_karp(src,tag));
        }
        return 0;
    }
  • 相关阅读:
    2.2 整数表示
    2.1 信息存储
    c++ string.erase()函数的使用
    classmethod修饰符
    27. 序列化
    26. 操作文件目录
    Java 内部类
    ConcurrentHashMap 源码解析 -- Java 容器
    Storm中的LocalState 代码解析
    Java中 return 和finally
  • 原文地址:https://www.cnblogs.com/Commence/p/4015641.html
Copyright © 2011-2022 走看看