• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 18,  comments - 5,  trackbacks - 0
            一、題目描述

            Description

            Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.
            Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
            Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

            Input

            The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.

            Output

            For each case, output a single integer, the maximum rate at which water may emptied from the pond.

            Sample Input

            5 4
            1 2 40
            1 4 20
            2 4 20
            2 3 30
            3 4 10
            

            Sample Output

            50

            二、分析
               其實(shí)就是以點(diǎn)1為s,以點(diǎn)m為t,求最大流,但是要注意輸入的路徑可以重復(fù)(見代碼30行),使用Edmonds-Karp算法,具體算法:最大流問題
            三、代碼
             1#include<iostream>
             2#include<queue>
             3using namespace std;
             4#define MAXM 201
             5int m, n;
             6int si, ei, ci;
             7int c[MAXM][MAXM];
             8int f[MAXM][MAXM];
             9int cf[MAXM][MAXM];
            10bool visit[MAXM];
            11int p[MAXM];
            12struct node
            13{
            14    int v, cf;
            15    void set(int vv, int ccf)
            16    {
            17        v = vv; cf = ccf;
            18    }

            19}
            ;
            20int main()
            21{
            22    while(scanf("%d%d"&n, &m) != EOF)
            23    {
            24        memset(c, 0sizeof(c));
            25        memset(f, 0sizeof(f));
            26        memset(cf, 0sizeof(cf));
            27        while(n--)
            28        {
            29            scanf("%d%d%d"&si, &ei, &ci);
            30            c[si][ei] += ci;
            31            cf[si][ei] = c[si][ei];
            32        }

            33        bool flag = true//用于表示是否找到增廣路
            34        while(flag)
            35        {
            36            flag = false;
            37            memset(visit, 0sizeof(visit));
            38            queue<node> q;
            39            node temp;
            40            temp.set(1, INT_MAX);
            41            p[1= 0;
            42            q.push(temp); visit[1= true;
            43            while(!q.empty()) //廣度優(yōu)先搜索
            44            {
            45                node temp = q.front(); q.pop();
            46                for(int i=1; i<=m; i++)
            47                {
            48                    if(temp.v == i || visit[i] || cf[temp.v][i] == 0)
            49                        continue;
            50                    node newNode; 
            51                    newNode.set(i, min(temp.cf, cf[temp.v][i]));
            52                    p[i] = temp.v;
            53                    q.push(newNode);
            54                    visit[i] = true;
            55                    if(i == m)
            56                    {
            57                        flag = true//找到增廣路
            58                        break;
            59                    }

            60                }

            61                if(flag)
            62                    break;
            63            }

            64            if(flag)
            65            {
            66                int mincf = q.back().cf;
            67                int v1 = p[m], v2 = m;
            68                while(v1 != 0)
            69                {
            70                    f[v1][v2] += mincf; //修改流
            71                    f[v2][v1] = -f[v1][v2];
            72                    cf[v1][v2] = c[v1][v2] - f[v1][v2]; //修改殘留容量
            73                    cf[v2][v1] = c[v2][v1] - f[v2][v1];
            74                    v2 = v1;
            75                    v1 = p[v1];
            76                }

            77            }

            78        }

            79        int res = 0;
            80        for(int i=2; i<=m; i++//計(jì)算最大流
            81            res += f[1][i];
            82        printf("%d\n", res);
            83    }

            84}
            posted on 2009-06-23 19:38 Icyflame 閱讀(2551) 評論(2)  編輯 收藏 引用 所屬分類: 解題報(bào)告
            国产L精品国产亚洲区久久| 久久精品免费一区二区| 99热都是精品久久久久久| 51久久夜色精品国产| 天堂久久天堂AV色综合| 国产激情久久久久影院| 日本加勒比久久精品| 大美女久久久久久j久久| 亚洲精品无码久久毛片 | 久久影院午夜理论片无码 | 亚洲中文字幕无码久久精品1| 久久久综合香蕉尹人综合网| 久久精品国产日本波多野结衣| 久久国产乱子伦精品免费强| 蜜臀av性久久久久蜜臀aⅴ | 欧美一级久久久久久久大片| 国内精品久久国产大陆| 久久久久久久波多野结衣高潮| 99久久国产综合精品成人影院| 久久夜色精品国产噜噜麻豆| 亚洲v国产v天堂a无码久久| 一本大道加勒比久久综合| 久久99精品久久久久久久久久| 国产成年无码久久久久毛片| 狠狠综合久久综合88亚洲| 亚洲国产日韩欧美综合久久| 久久精品亚洲欧美日韩久久| 久久中文精品无码中文字幕| 91亚洲国产成人久久精品| 久久A级毛片免费观看| 精品久久久久久久久久中文字幕 | 亚洲va国产va天堂va久久| 热99RE久久精品这里都是精品免费| 久久久久久久久久久| 狠狠色丁香久久婷婷综合蜜芽五月| 欧美与黑人午夜性猛交久久久| 久久久久黑人强伦姧人妻 | 久久er99热精品一区二区| 精品免费久久久久久久| 国产精品久久久久久福利69堂| 久久免费香蕉视频|