• <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>

            poj1273

            Drainage Ditches

            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 37500 Accepted: 13862

            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
            話說這是道網絡流的模版題,鄙人沒寫過多少網絡流,于是忍不住來練練手
            邪惡的是,我打了模版之后,才發現我模版好多錯誤(自己改的模版),悲劇
            然后終于改好了,然后一直wa,
            不解,重邊我也處理了呀,怎么搞的,
            然后去看discuss,忽然發現一組數據
            input:
            3 2
            1 2 3
            1 2 4
            1 2 5
            output:
            12
            頓時無語了,原來重邊在這里要相加啊,我開始取得min,后來取得max
            呃,表示自己真心是水貨
              1#include<stdio.h>
              2#include<string.h>
              3#include<math.h>
              4#define MAX 205
              5#define inf 0x7fffffff
              6int n,m,s,t;
              7int map[MAX][MAX];
              8int d[MAX],r[MAX][MAX],num[MAX],pre[MAX];
              9int min(int a,int b)
             10{
             11    if(a<b) return a;
             12    else return b;
             13}

             14int void bfs()
             15{
             16    int i,k;
             17    int q[MAX*MAX],head,tail;
             18    for(i=1;i<=n;i++)
             19        d[i]=n+1;
             20    memset(num,0,sizeof(num));
             21    head=0;
             22    tail=1;
             23    q[tail]=t;
             24    d[t]=0;
             25    num[0]=1;
             26    while(head<tail)
             27    {
             28        head++;
             29        k=q[head];
             30        for(i=1; i<=n; i++)
             31        {
             32            if(d[i]>n&&r[i][k]>0)
             33            {
             34                d[i]=d[k]+1;
             35                tail++;
             36                q[tail]=i;
             37                num[d[i]]++;
             38            }

             39        }

             40    }

             41}

             42int findalowarc(int i)
             43{
             44    int j;
             45    for(j=1; j<=n; j++)
             46        if((r[i][j]>0)&&(d[i]==d[j]+1)) return j;
             47    return -1;
             48}

             49int relabel(int i)
             50{
             51    int j;
             52    int mm=inf;
             53    for(j=1; j<=n; j++)
             54    {
             55        if (r[i][j]>0) mm=min(mm,d[j]+1);
             56    }

             57    return (mm==inf)?n:mm;
             58}

             59int maxflow()
             60{
             61    int flow,i,j,delta;
             62    int x;
             63    bfs();
             64    i=s;
             65    flow=0;
             66    memset(pre,-1,sizeof(pre));
             67    while(d[s]<=n)
             68    {
             69        j=findalowarc(i);
             70        if(j>0)
             71        {
             72            pre[j]=i;
             73            i=j;
             74            if(i==t)
             75            {
             76                delta=inf;
             77                for(i=t; i!=s; i=pre[i])
             78                    delta=min(delta,r[pre[i]][i]);
             79                for(i=t; i!=s; i=pre[i])
             80                {
             81                    r[pre[i]][i]-=delta;
             82                    r[i][pre[i]]+=delta;
             83                }

             84                flow+=delta;
             85            }

             86        }

             87        else
             88        {
             89            x=relabel(i);
             90            num[x]++;
             91            num[d[i]]--;
             92            if(num[d[i]]==0return flow;//間隙優化
             93            d[i]=x;
             94            if(i!=s) i=pre[i];
             95        }

             96    }

             97    return flow;
             98}

             99int main()
            100{
            101    int i,j;
            102    int x,y,z;
            103    while (scanf("%d%d",&m,&n)!=EOF)
            104    {
            105        s=1;
            106        t=n;
            107        memset(map,0,sizeof(map));
            108        for (i=1; i<=m; i++ )
            109        {
            110            scanf("%d%d%d",&x,&y,&z);
            111            if (map[x][y]==0)
            112            {
            113                map[x][y]=z;
            114            }

            115            else
            116            {
            117                map[x][y]=map[x][y]+z;
            118            }

            119        }

            120        for(i=1; i<=n; i++)
            121            for(j=1; j<=n; j++)
            122                r[i][j]=map[i][j];
            123        printf("%d\n",maxflow());
            124    }

            125    return 0;
            126}

            127
             還發現個問題
            我寫的sap怎么跑了16ms,同學寫的ek才跑了0ms
            why??

            posted on 2012-03-14 00:20 jh818012 閱讀(356) 評論(1)  編輯 收藏 引用

            評論

            # re: poj1273 2012-03-20 10:02 王私江

            哈哈哈,您弱爆了!!  回復  更多評論   

            <2012年3月>
            26272829123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            激情五月综合综合久久69| 亚洲AV无码久久精品成人| 久久精品国产亚洲麻豆| 国产精品VIDEOSSEX久久发布| 99热都是精品久久久久久| 99久久综合国产精品二区| 最新久久免费视频| 99久久免费国产特黄| 日韩va亚洲va欧美va久久| 久久棈精品久久久久久噜噜| 久久久精品久久久久久| 久久精品无码午夜福利理论片 | 精品水蜜桃久久久久久久| 久久91精品国产91| 成人a毛片久久免费播放| 午夜精品久久久久| 狠狠精品久久久无码中文字幕| 99久久夜色精品国产网站| 狠狠精品久久久无码中文字幕| 久久久久亚洲AV无码网站| 亚洲午夜精品久久久久久浪潮 | 久久经典免费视频| 狠狠精品干练久久久无码中文字幕| 中文精品久久久久人妻不卡| 久久久久久无码国产精品中文字幕| 久久99精品久久久久久久不卡 | 久久精品夜色噜噜亚洲A∨| 麻豆成人久久精品二区三区免费 | 亚洲精品无码专区久久同性男| 99精品国产在热久久无毒不卡| 久久亚洲AV无码精品色午夜| 久久无码AV中文出轨人妻| 色综合久久久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 色婷婷久久综合中文久久一本| 国产午夜电影久久| 久久91这里精品国产2020| 99久久精品国产麻豆| 精品国产一区二区三区久久久狼| 久久综合国产乱子伦精品免费| 人妻无码久久一区二区三区免费|