青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

poj1459

Power Network

Time Limit: 2000MS Memory Limit: 32768K
Total Submissions: 16422 Accepted: 8712

Description

A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= pmax(u) of power, may consume an amount 0 <= c(u) <= min(s(u),cmax(u)) of power, and may deliver an amount d(u)=s(u)+p(u)-c(u) of power. The following restrictions apply: c(u)=0 for any power station, p(u)=0 for any consumer, and p(u)=c(u)=0 for any dispatcher. There is at most one power transport line (u,v) from a node u to a node v in the net; it transports an amount 0 <= l(u,v) <= lmax(u,v) of power delivered by u to v. Let Con=Σuc(u) be the power consumed in the net. The problem is to compute the maximum value of Con.

An example is in figure 1. The label x/y of power station u shows that p(u)=x and pmax(u)=y. The label x/y of consumer u shows that c(u)=x and cmax(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and lmax(u,v)=y. The power consumed is Con=6. Notice that there are other possible states of the network but the value of Con cannot exceed 6.

Input

There are several data sets in the input. Each data set encodes a power network. It starts with four integers: 0 <= n <= 100 (nodes), 0 <= np <= n (power stations), 0 <= nc <= n (consumers), and 0 <= m <= n^2 (power transport lines). Follow m data triplets (u,v)z, where u and v are node identifiers (starting from 0) and 0 <= z <= 1000 is the value of lmax(u,v). Follow np doublets (u)z, where u is the identifier of a power station and 0 <= z <= 10000 is the value of pmax(u). The data set ends with nc doublets (u)z, where u is the identifier of a consumer and 0 <= z <= 10000 is the value of cmax(u). All input numbers are integers. Except the (u,v)z triplets and the (u)z doublets, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct.

Output

For each data set from the input, the program prints on the standard output the maximum amount of power that can be consumed in the corresponding network. Each result has an integral value and is printed from the beginning of a separate line.

Sample Input

2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20
7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7
         (3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5
         (0)5 (1)2 (3)2 (4)1 (5)4

Sample Output

15
6

Hint

The sample input contains two data sets. The first data set encodes a network with 2 nodes, power station 0 with pmax(0)=15 and consumer 1 with cmax(1)=20, and 2 power transport lines with lmax(0,1)=20 and lmax(1,0)=10. The maximum value of Con is 15. The second data set encodes the network from figure 1.


哎,糾結死了,我對網絡流這方面理解的還不行

如果自己寫代碼的話還是有點難度,所以找個好的模版還是很重要的

額,模版也比較糾結,好多中算法

找了個比較簡單的算法 Edmonds_karp 

時間復雜度為O(V*E^2)

Edmonds-Karp算法就是利用寬度優先不斷地找一條從s到t的可改進路,然后改進流量,一直到找不到可改進路為止。

由于用寬度優先,每次找到的可改進路是最短的可改進路,通過分析可以知道其復雜度為O(VE^2)。

代碼好丑
  1#include<stdio.h>
  2#include<string.h>
  3#include<math.h>
  4#define MAX 105
  5int map[MAX][MAX],flow[MAX][MAX],c[MAX][MAX];
  6int n,nc,np,nt,s,t;
  7int sum;
  8int min(int a,int b)
  9{
 10    if (a<b) return a;else return b;
 11}

 12void Edmonds_Karp()
 13{
 14    int l1[MAX],l2[MAX],q[MAX];
 15    int u,v,head,tail;
 16    do 
 17    {
 18        memset(l1,0,sizeof(l1));
 19        memset(l2,0,sizeof(l2));//初始化所有標號為0
 20        l1[s]=0;l2[s]=0x7fffffff;
 21        head=0;tail=1;
 22        q[tail]=s;
 23        while (head<tail&&l2[t]==0)//q未空且匯點未標號
 24        {
 25            head++;
 26            u=q[head];
 27            for (v=1;v<=n ;v++ )
 28            {
 29                if (flow[u][v]<c[u][v]&&l2[v]==0)//未標號且有可行流
 30                {
 31                    tail++;
 32                    q[tail]=v;
 33                    l2[v]=min(c[u][v]-flow[u][v],l2[u]);
 34                    //l2[v]記錄s到v增廣路中最小的可改進流
 35                    l1[v]=u;//記錄前驅
 36                }

 37            }

 38        }

 39        if (l2[t]>0)//匯點未標號
 40        {
 41            v=t;
 42            u=l1[v];
 43            while (v!=s)
 44            {
 45                flow[u][v]+=l2[t];
 46                flow[v][u]=-flow[u][v];
 47                v=u;
 48                u=l1[v];
 49            }

 50        }

 51    }

 52    while (l2[t]!=0);//直到匯點未標號
 53}

 54void init()
 55{
 56    int i,j,a,b,w,x;
 57    char ch1;
 58    s=1;t=n+2;
 59    memset(map,0,sizeof(map));
 60    for (i=1;i<=nt ;i++ )
 61    {
 62        scanf("%c",&ch1);
 63        while (ch1!='(')
 64        {
 65            scanf("%c",&ch1);
 66        }

 67        scanf("%d",&a);a=a+2;
 68        scanf("%c",&ch1);scanf("%d",&b);b=b+2;
 69        scanf("%c",&ch1);scanf("%d",&w);
 70        map[a][b]=w;
 71    }

 72    for (i=1;i<=np ;i++ )
 73    {
 74        scanf("%c",&ch1);
 75        while (ch1!='(')
 76        {
 77            scanf("%c",&ch1);
 78        }

 79        scanf("%d",&a);a=a+2;
 80        scanf("%c",&ch1);scanf("%d",&w);
 81        map[s][a]=w;//map[a][s]=-w;
 82    }

 83    for (i=1;i<=nc ;i++ )
 84    {
 85        scanf("%c",&ch1);
 86        while (ch1!='(')
 87        {
 88            scanf("%c",&ch1);
 89        }

 90        scanf("%d",&a);a=a+2;
 91        scanf("%c",&ch1);scanf("%d",&w);
 92        map[a][t]=w;//map[t][a]=-w;
 93    }

 94    n=n+2;
 95    /*/for (i=1;i<=n ;i++ )
 96    {
 97        for (j=1;j<=n;j++ )
 98        {
 99            printf("%d ",map[i][j]);
100        }
101        printf("\n");
102    }*/

103    for (i=1;i<=n ;i++ )
104    {
105        for (j=1;j<=n;j++ )
106        {
107            c[i][j]=map[i][j];
108        }

109    }

110}

111int main()
112{
113    int i;
114    while (scanf("%d%d%d%d",&n,&np,&nc,&nt)!=EOF)
115    {
116        memset(flow,0,sizeof(flow));
117        init();
118        Edmonds_Karp(1,n);
119        sum=0;
120        for (i=1;i<=n;i++ )
121        {
122            sum+=flow[1][i];
123        }

124        printf("%d\n",sum);
125    }

126    return 0;
127}

128



posted on 2012-02-23 17:34 jh818012 閱讀(136) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導航

統計

常用鏈接

留言簿

文章檔案(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
  • 評論內容較長,點擊標題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲综合精品自拍| 国产精品天天看| 午夜在线精品偷拍| 欧美高清视频www夜色资源网| 久久99在线观看| 国产精品久久久久久久久久免费 | 99re66热这里只有精品4| 亚洲欧洲综合另类| 麻豆成人在线| 欧美二区在线| 亚洲激情在线观看| 美女网站久久| 亚洲国产小视频在线观看| 激情av一区二区| 久久蜜臀精品av| 欧美+日本+国产+在线a∨观看| 国产综合第一页| 久久久99免费视频| 欧美一区二区女人| 国产欧美 在线欧美| 亚洲一区在线观看免费观看电影高清| 亚洲视频一区二区免费在线观看| 免费视频一区二区三区在线观看| 你懂的一区二区| 一区在线视频| 欧美中文在线免费| 亚洲免费成人| 狂野欧美一区| 欧美成人a视频| 在线观看国产日韩| 久久夜色精品亚洲噜噜国产mv| 久久综合五月| 在线日韩av| 欧美96在线丨欧| 欧美黄色免费| 亚洲伦理在线免费看| 欧美不卡在线| 91久久精品一区二区别| 99在线精品免费视频九九视| 欧美激情亚洲视频| 亚洲毛片在线| 亚洲欧美日韩一区| 国产欧美一区二区三区国产幕精品| 亚洲一级黄色av| 欧美一区二区三区精品电影| 国产欧美视频一区二区| 久久九九免费视频| 亚洲国产精品999| 一区二区三区黄色| 国产精品一卡二| 欧美一级二区| 欧美福利在线观看| 一本色道久久| 国产精品欧美日韩久久| 欧美一区二区免费| 欧美激情精品久久久六区热门 | 免费一区二区三区| 久久人人爽人人爽爽久久| 国产欧美 在线欧美| 亚洲一级特黄| 久久久成人精品| 免费观看日韩av| 欧美va天堂va视频va在线| 欧美黑人国产人伦爽爽爽| 最近看过的日韩成人| 一区二区三区四区五区视频 | 久久综合国产精品| 午夜免费久久久久| 国产亚洲一本大道中文在线| 久久亚洲美女| 亚洲专区欧美专区| 你懂的视频一区二区| 在线视频一区二区| 欧美日韩国产精品一卡| 亚洲欧洲日韩在线| 亚洲免费一在线| 国产亚洲精品福利| 欧美日韩国产三级| 久久久久久亚洲综合影院红桃 | 狠狠综合久久av一区二区老牛| 欧美另类在线播放| 欧美一区二区在线| 亚洲精品美女在线| 久久亚洲影院| 亚洲欧美日韩一区二区| 亚洲日本一区二区| 欧美视频在线视频| 亚洲男女自偷自拍| 亚洲一区视频| 黑人巨大精品欧美一区二区| 米奇777超碰欧美日韩亚洲| 欧美区在线观看| 久久久夜夜夜| 亚洲午夜国产一区99re久久 | 欧美区一区二| 久久久亚洲人| 亚洲亚洲精品三区日韩精品在线视频| 欧美国产日本在线| 久久久久国产精品麻豆ai换脸| 99re6这里只有精品视频在线观看| 国产欧美一区二区三区久久| 欧美午夜精品| 欧美破处大片在线视频| 蜜桃精品久久久久久久免费影院| 性欧美videos另类喷潮| 亚洲视频免费在线| 99精品国产在热久久| 亚洲国产视频直播| 欧美3dxxxxhd| 久久久噜噜噜久久| 亚洲一区三区视频在线观看| 一区二区av在线| 韩日精品在线| 欧美性事免费在线观看| 麻豆免费精品视频| 亚洲一区二区三区欧美| 亚洲激情在线播放| 免费在线日韩av| 久久久噜噜噜久久中文字幕色伊伊 | 国产精自产拍久久久久久蜜 | 亚洲欧洲在线免费| 久久亚洲一区二区三区四区| 亚洲精品一区中文| 久久综合五月| 午夜精品视频在线| 91久久精品日日躁夜夜躁国产| 麻豆成人在线播放| 亚洲天堂久久| 一区二区三区在线观看欧美 | 亚洲欧美日韩一区二区在线| 一区二区三区日韩精品| 一二三区精品福利视频| 亚洲少妇在线| 亚洲精品国久久99热| 亚洲在线中文字幕| 欧美一区观看| 久久久久网站| 欧美黄色大片网站| 日韩一级在线观看| 亚洲精品字幕| 亚洲天堂久久| 久久爱www| 蜜桃久久av一区| 欧美另类videos死尸| 国产精品久久久一区二区| 国产视频精品xxxx| 1204国产成人精品视频| 亚洲精品三级| 香蕉久久夜色精品国产| 欧美一区二区三区四区高清 | 久久在线免费观看| 欧美理论片在线观看| 国产精品欧美一区喷水 | 久久久久一区| 欧美日韩国产高清| 国产女主播在线一区二区| 在线成人国产| 国内精品久久久久伊人av| 亚洲日本欧美在线| 午夜精品久久久久久久久久久久久 | 亚洲精品乱码久久久久久久久| 欧美福利一区二区三区| 99视频精品免费观看| 欧美在线1区| 欧美精品一区视频| 国产综合色产| 99re8这里有精品热视频免费| 午夜精品久久久久久久久久久| 久久综合99re88久久爱| 亚洲国产精品一区二区久| 亚洲视频播放| 久久久亚洲高清| 欧美日韩亚洲三区| 亚洲人永久免费| 午夜日本精品| 亚洲理伦在线| 久久夜色精品国产噜噜av| 国产日韩高清一区二区三区在线| 亚洲精品美女在线| 亚洲人成亚洲人成在线观看图片| 亚洲视频专区在线| 欧美成人精品激情在线观看| 一区二区三区日韩精品| 久久人人爽国产| 欧美午夜一区| 亚洲欧洲综合| 久久视频在线免费观看| 99国产精品| 久久综合五月天婷婷伊人| 欧美精品一区二区在线播放| 国产精品久久久久77777| 国产综合香蕉五月婷在线| 亚洲国产岛国毛片在线| 亚洲图中文字幕| 欧美成人在线免费观看| 欧美一级黄色网| 欧美黄色aa电影| 国产婷婷97碰碰久久人人蜜臀| 亚洲日本成人| 欧美亚洲一区在线|