hdu4009 Transfer water 最小树形图】的更多相关文章

题目链接:https://vjudge.net/problem/HDU-4009 Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 5612    Accepted Submission(s): 1997 Problem Description XiaoA lives in a village. Last ye…
每一户人家水的来源有两种打井和从别家接水,每户人家都可能向外输送水. 打井和接水两种的付出代价都接边.设一个超级源点,每家每户打井的代价就是从该点(0)到该户人家(1~n)的边的权值.接水有两种可能,从高处接水,那么代价是哈密顿距离与Y的乘积(可以认为就是水管的费用):从低处接水,还要加上付出水泵的钱(水管+水泵的费用).这样就可以建图了.图论,会建图的话问题就解决一半了. 然后,用模版来解题.不过朱刘算法的模版时间复杂度的差异还是蛮大的.我的模版的建图是邻接矩阵,时间复杂度是O(N^3).超时…
分析:建一个远点,往每个点连建井的价值(单向边),其它输水线按照题意建单向边 然后以源点为根的权值最小的有向树就是答案,套最小树形图模板 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <stack> #include <…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 4216    Accepted Submission(s): 1499 Problem Description XiaoA lives in a village. Last year flood rained the village. So they dec…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3775    Accepted Submission(s): 1356 Problem Description XiaoA lives in a village. Last year flood rained the village. So they dec…
最小树形图求的是有向图的最小生成树,跟无向图求最小生成树有很大的区别. 步骤大致如下: 1.求除了根节点以外每个节点的最小入边,记录前驱 2.判断除了根节点,是否每个节点都有入边,如果存在没有入边的点,说明树形图不存在,退出. 3.沿着节点的前驱找,如果发现环,把环缩点. 4.如果不存在环,结束.否则,跳到1. 其实我是来贴模板的... 比较好的讲解:最小树型图的求解与实现 代码讲解比较好的:hdu4009 Transfer water ( 最小树形图的模板 ) 用IO优化时死活TLE,改了sc…
Transfer water Time Limit:3000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4009 Description XiaoA lives in a village. Last year flood rained the village. So they decide to move the whole village to the moun…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 题意:给出一个村庄(x,y,z).每个村庄可以挖井或者修建水渠从其他村庄得到水.挖井有一个代价,修水渠有一个代价.另外A村庄只能向其指定的一些村庄供水.使得所有村庄有水求最小代价. 思路:增加虚拟点0,向所有点连边表示挖井.能连边的连边.求最小树形图即可. struct point { int x,y,z; }; struct edge { int u,v,w; }; point p[N];…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3821    Accepted Submission(s): 1371 Problem Description XiaoA lives in a village. Last year flood rained the village. So they dec…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 6126    Accepted Submission(s): 2181 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 Description: XiaoA lives in a village. Las…