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;
    }
  • 相关阅读:
    原来这样就可以开发出一个百万量级的Android相机
    微信读书这样排版,看过的人都很难忘!
    AI小白快上车!这是发往高薪职位的车!
    短视频APP是如何开启你的美好生活的?
    自从我这样撸代码以后,公司网页的浏览量提高了107%!
    如果想成为一名顶尖的前端,这份书单你一定要收藏!
    老板今天问我为什么公司的数据库这么烂,我是这样回答的......
    MapReduce Notes
    HDFS Architecture Notes
    BloomFilter
  • 原文地址:https://www.cnblogs.com/Commence/p/4015641.html
Copyright © 2011-2022 走看看