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

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
 

今年大連賽區網絡賽一道題.....我怎么一點印象也沒有呢.....
一道赤裸的最小樹形圖,除了數據有點大而已.....
思路:因為沒有根,所以虛擬一個根,所有點和這個根連線,權值是該點造井的價格,這樣以這個根出發,構造出來的最小樹形圖就是最小的費用了。
代碼:
#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 閱讀(253) 評論(0)  編輯 收藏 引用 所屬分類: 圖論
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲精选一区| 亚洲国产一区二区精品专区| 一区二区欧美在线| 91久久久在线| 欧美激情第一页xxx| 亚洲三级免费观看| 亚洲人成在线播放网站岛国| 欧美日韩一区二区三| 午夜视频一区在线观看| 亚洲一区精彩视频| 精品1区2区3区4区| 亚洲丶国产丶欧美一区二区三区| 99精品国产在热久久| 亚洲精品之草原avav久久| 欧美三级乱码| 久久久五月天| 欧美日本国产视频| 欧美一区二区精美| 老牛嫩草一区二区三区日本 | 日韩视频永久免费| 亚洲国产免费| 欧美电影免费观看大全| 欧美11—12娇小xxxx| 亚洲精品国偷自产在线99热| 在线一区二区日韩| 狠狠色噜噜狠狠狠狠色吗综合| 夜夜爽夜夜爽精品视频| 亚洲一区二区在线看| 国产亚洲欧洲997久久综合| 男女激情久久| 国产精品亚洲成人| 欧美黄色aa电影| 国产老女人精品毛片久久| 欧美国产激情| 国产欧美在线播放| 亚洲精品国产精品国自产在线| 久久躁狠狠躁夜夜爽| 亚洲欧美日韩在线综合| 久久综合伊人77777| 亚洲欧美精品伊人久久| 欧美成ee人免费视频| 在线一区二区视频| 久久青草福利网站| 久久大逼视频| 欧美日韩另类综合| 欧美激情在线狂野欧美精品| 国产日韩精品综合网站| 日韩视频三区| 亚洲黄色免费| 久久天天躁狠狠躁夜夜爽蜜月| 国精品一区二区三区| 一个色综合导航| 亚洲美女诱惑| 另类激情亚洲| 久久一二三区| 国产综合在线看| 午夜伦欧美伦电影理论片| 亚洲午夜一二三区视频| 欧美精品一区视频| 亚洲电影在线看| 亚洲大胆人体视频| 久久久噜噜噜久久人人看| 久久精品国产在热久久| 国产欧美一区视频| 在线视频亚洲欧美| 午夜一区不卡| 国产精品影片在线观看| 亚洲综合色网站| 香蕉精品999视频一区二区| 欧美午夜电影在线| 亚洲视频精选| 小黄鸭精品aⅴ导航网站入口| 久久久国产精彩视频美女艺术照福利 | 中文精品99久久国产香蕉| 欧美国产日韩一区| 亚洲精品一区久久久久久| 日韩视频三区| 欧美性大战xxxxx久久久| 9色porny自拍视频一区二区| 亚洲午夜精品久久| 国产乱码精品一区二区三| 亚洲欧美日韩一区| 久久亚洲精品伦理| 亚洲经典三级| 欧美日韩国产va另类| 亚洲精品欧美一区二区三区| 亚洲视频一区在线| 国产精品午夜国产小视频| 欧美在线看片a免费观看| 久久伊人亚洲| 一本综合精品| 国产日韩欧美亚洲| 欧美a级一区二区| 99精品视频免费全部在线| 欧美与黑人午夜性猛交久久久| 欧美国产精品久久| 一区二区三区色| 久久人人爽人人爽| 亚洲国产精品黑人久久久| 欧美欧美天天天天操| 亚洲男同1069视频| 欧美aaa级| 亚洲欧美清纯在线制服| 樱桃成人精品视频在线播放| 欧美美女福利视频| 欧美一级二区| 亚洲精品小视频在线观看| 欧美中文在线观看国产| 亚洲精品美女在线观看播放| 国产精品亚洲综合一区在线观看| 亚洲精选一区| 久久久久久久久一区二区| 亚洲美洲欧洲综合国产一区| 欧美性片在线观看| 久热re这里精品视频在线6| 9人人澡人人爽人人精品| 欧美1区2区视频| 欧美亚洲专区| 亚洲视频在线观看视频| 伊人久久综合| 国产日韩欧美日韩| 国产精品h在线观看| 欧美14一18处毛片| 久久九九热re6这里有精品| 亚洲一区二区三区四区视频| 欧美风情在线观看| 久久综合精品国产一区二区三区| 黑人巨大精品欧美一区二区| 欧美日韩一区二| 欧美国产第一页| 美国十次成人| 欧美亚洲色图校园春色| 亚洲激情不卡| 欧美福利视频在线| 免费在线成人| 久热re这里精品视频在线6| 欧美一级黄色网| 亚洲影院色在线观看免费| 亚洲人精品午夜| 亚洲第一黄色| 亚洲国产精品毛片| 在线精品视频免费观看 | 亚洲破处大片| 欧美国产日韩一区| 久久久久一区二区| 久久se精品一区精品二区| 性刺激综合网| 午夜精品福利视频| 午夜一区二区三区不卡视频| 亚洲欧美日韩国产中文| 午夜一区二区三区在线观看| 午夜久久久久久久久久一区二区| 激情综合色综合久久综合| 激情综合激情| 在线欧美三区| 亚洲精品黄色| 一区二区三区精密机械公司| 亚洲影视综合| 欧美在线日韩精品| 久久中文在线| 亚洲国产成人av好男人在线观看| 99精品热视频| 亚洲制服丝袜在线| 欧美在线观看视频一区二区三区| 一色屋精品视频免费看| 亚洲国产裸拍裸体视频在线观看乱了 | 亚洲国产高潮在线观看| 亚洲精品国产视频| 亚洲小少妇裸体bbw| 亚洲欧美日韩高清| 久久免费午夜影院| 欧美久久婷婷综合色| 国产精品成人播放| 国内成人精品2018免费看| 亚洲成色777777在线观看影院| 欧美三级韩国三级日本三斤| 国产精品网站一区| 国产综合一区二区| 亚洲人成亚洲人成在线观看图片| 国产日韩欧美| 亚洲精品乱码久久久久久蜜桃91 | 欧美日韩视频在线一区二区 | 欧美在线日韩精品| 久久久xxx| 欧美三级资源在线| 一区二区在线免费观看| 亚洲视频在线观看| 麻豆国产精品va在线观看不卡| 久久成人综合视频| 亚洲激情女人| 久久精品视频一| 国产精品久久福利| 国内自拍亚洲| 亚洲一区二区三区精品在线| 蜜臀va亚洲va欧美va天堂| 夜夜嗨av一区二区三区| 久久久夜精品| 国产日韩久久| 亚洲免费在线观看视频| 亚洲国产高清一区二区三区|