• <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 - 7,comments - 3,trackbacks - 0

            Transfer water

            Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
            Total Submission(s): 1770    Accepted Submission(s): 650


            Problem Description
            XiaoA lives in a village. Last year flood rained the village. So they decide to move the whole village to the mountain nearby this year. There is no spring in the mountain, so each household could only dig a well or build a water line from other household. If the household decide to dig a well, the money for the well is the height of their house multiplies X dollar per meter. If the household decide to build a water line from other household, and if the height of which supply water is not lower than the one which get water, the money of one water line is the Manhattan distance of the two households multiplies Y dollar per meter. Or if the height of which supply water is lower than the one which get water, a water pump is needed except the water line. Z dollar should be paid for one water pump. In addition,therelation of the households must be considered. Some households may do not allow some other households build a water line from there house. Now given the 3‐dimensional position (a, b, c) of every household the c of which means height, can you calculate the minimal money the whole village need so that every household has water, or tell the leader if it can’t be done.
             

            Input
            Multiple cases. 
            First line of each case contains 4 integers n (1<=n<=1000), the number of the households, X (1<=X<=1000), Y (1<=Y<=1000), Z (1<=Z<=1000). 
            Each of the next n lines contains 3 integers a, b, c means the position of the i‐th households, none of them will exceeded 1000. 
            Then next n lines describe the relation between the households. The n+i+1‐th line describes the relation of the i‐th household. The line will begin with an integer k, and the next k integers are the household numbers that can build a water line from the i‐th household. 
            If n=X=Y=Z=0, the input ends, and no output for that. 
             

            Output
            One integer in one line for each case, the minimal money the whole village need so that every household has water. If the plan does not exist, print “poor XiaoA” in one line. 
             

            Sample Input
            2 10 20 30 1 3 2 2 4 1 1 2 2 1 2 0 0 0 0
             

            Sample Output
            30
            Hint
            In 3‐dimensional space Manhattan distance of point A (x1, y1, z1) and B(x2, y2, z2) is |x2‐x1|+|y2‐y1|+|z2‐z1|.
             

            Source
             

            Recommend
            lcy
             

            今年大連賽區(qū)網(wǎng)絡(luò)賽一道題.....我怎么一點(diǎn)印象也沒有呢.....
            一道赤裸的最小樹形圖,除了數(shù)據(jù)有點(diǎn)大而已.....
            思路:因?yàn)闆]有根,所以虛擬一個根,所有點(diǎn)和這個根連線,權(quán)值是該點(diǎn)造井的價格,這樣以這個根出發(fā),構(gòu)造出來的最小樹形圖就是最小的費(fèi)用了。
            代碼:
            #include <cstdio>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <iostream>
            using namespace std;

            const int maxn = 1100;
            const int maxm = 1100000;
            const int maxint = 0x3fffffff;

            struct edge
            {
                
            int u, v, w;
                edge(){}
                edge(
            int u1, int v1, int w1) : u(u1), v(v1), w(w1){}
            } e[maxm];

            int root, n, edgeNum, vis[maxn], pre[maxn], belong[maxn], in[maxn];
            int a[maxn], b[maxn], c[maxn];
            int Abs(int a)
            {
                
            return a > 0 ? a : -a;
            }

            int Dis(int i, int j)
            {
                
            return Abs(a[i] - a[j]) + Abs(b[i] - b[j]) + Abs(c[i] - c[j]);
            }

            int solve()
            {
                
            int i, j, k, num, sum = 0;
                n
            ++;
                
            while (1)
                {
                    
            for (i = 0; i < n; ++i)
                        
            in[i] = maxint;
                    
            for (i = 0; i < edgeNum; ++i)
                    {
                        
            if (in[e[i].v] > e[i].w && e[i].u != e[i].v)
                        {
                            pre[e[i].v] 
            = e[i].u;
                            
            in[e[i].v] = e[i].w;
                        }
                    }

                    memset(vis, 
            -1sizeof(vis));
                    memset(belong, 
            -1sizeof(belong));
                    
            in[root] = 0;
                    
            for (num = 0, i = 0; i < n; ++i)
                    {
                        sum 
            += in[i];
                        j 
            = i;
                        
            while (vis[j] != i && belong[j] == -1 && j != root)
                        {
                            vis[j] 
            = i;
                            j 
            = pre[j];
                        }
                        
            if (vis[j] == i)
                        {
                            
            for (k = pre[j]; k != j; k = pre[k])
                                belong[k] 
            = num;
                            belong[j] 
            = num++;
                        }
                    }

                    
            if (!num) return sum;
                    
            for (i = 0; i < n; ++i)
                        
            if (belong[i] == -1)
                            belong[i] 
            = num++;

                    
            for (i = 0; i < edgeNum; ++i)
                    {
                        
            int j = e[i].v;
                        e[i].u 
            = belong[e[i].u];
                        e[i].v 
            = belong[e[i].v];
                        e[i].w 
            -= in[j];
                    }
                    n 
            = num;
                    root 
            = belong[root];
                }
                
            return sum;
            }

            int main()
            {
                
            int x, y, z, i, j, k, ii, d;
                
            while (scanf("%d%d%d%d"&n, &x, &y, &z) != EOF)
                {
                    
            if (!&& !&& !&& !z) break;
                    
            for (edgeNum = 0, i = 1; i <= n; ++i)
                    {
                        scanf(
            "%d%d%d"&a[i], &b[i], &c[i]);
                        e[edgeNum
            ++= edge(0, i, c[i] * x);
                    }
                    
            for (i = 1; i <= n; ++i)
                    {
                        scanf(
            "%d"&k);
                        
            while (k--)
                        {
                            scanf(
            "%d"&ii);
                            
            if (i == ii) continue;
                            d 
            = Dis(i, ii);
                            
            if (c[i] >= c[ii])
                                e[edgeNum
            ++= edge(i, ii, d * y);
                            
            else
                                e[edgeNum
            ++= edge(i, ii, d * y + z);
                        }
                    }

                    root 
            = 0;
                    printf(
            "%d\n", solve());
                }
                
            return 0;
            }
            posted on 2011-10-15 22:20 LLawliet 閱讀(232) 評論(0)  編輯 收藏 引用 所屬分類: 圖論
            亚洲欧洲精品成人久久奇米网| 一本色道久久综合狠狠躁篇| 亚洲中文字幕无码久久综合网| 伊人久久无码精品中文字幕| 久久精品国产亚洲av麻豆图片| 国产69精品久久久久9999APGF| 天天躁日日躁狠狠久久| 人妻精品久久无码专区精东影业| 午夜精品久久久久久久久| 99久久久国产精品免费无卡顿 | 久久国产精品-国产精品| 久久久久久久综合日本亚洲| 26uuu久久五月天| 亚洲七七久久精品中文国产| 色婷婷综合久久久久中文 | 久久综合久久综合亚洲| 亚洲精品乱码久久久久久蜜桃不卡 | 91性高湖久久久久| 一级A毛片免费观看久久精品| 久久夜色精品国产噜噜亚洲AV| 国产成人精品久久一区二区三区av| 久久影院亚洲一区| 国产精品久久久久久久久| 久久人人爽人人爽人人片AV麻豆 | 久久久精品2019免费观看| 国产亚洲精久久久久久无码AV| 久久精品卫校国产小美女| 久久精品嫩草影院| 亚洲精品tv久久久久久久久| 久久亚洲国产午夜精品理论片| 国产成人精品久久| 久久久免费观成人影院 | 青草影院天堂男人久久| 天堂久久天堂AV色综合| 一本色综合久久| 久久九九久精品国产| 久久综合综合久久97色| 99精品久久精品| 精品久久久久久中文字幕| 久久久无码一区二区三区| 久久久久se色偷偷亚洲精品av |