Destroy Walls Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1774    Accepted Submission(s): 689 Problem Description Long times ago, there are beautiful historic walls in the city. These wal…
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1784 Accepted Submission(s): 692 * Problem Description Long times ago, there are beautiful histor…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4477    Accepted Submission(s): 1124 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187 题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费. 解法: #include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int maxm = 200010; struct edge{ int u,v,w; edge(){} bool…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5723 n个村庄m条双向路,从中要选一些路重建使得村庄直接或间接相连且花费最少,这个问题就是很明显的求最小生成树,由于边权各不相同,所以最小生成树唯一. 然后,在这个最小生成树的基础上,求各个路径的最小期望和(推导出 期望 = 所有村庄中任意两个村庄距离之和 / 村庄对数). 最小生成树很好求(边权从小到大,并查集一下就好了). 然后求以上基础村庄中任意两个村庄距离之和,只要求每条边乘上每条边出现的次…
苗条的生成树 紫书P358 这题最后坑了我20分钟,怎么想都对了啊,为什么就wa了呢,最后才发现,是并查集的编号搞错了. 题目编号从1开始,我并查集编号从0开始 = = 图论这种题真的要记住啊!!题目大部分都是从1开始编号,而代码大部分是从0开始编号,所以要把输入减减. [题目链接]苗条的生成树 [题目类型]最小生成树+并查集 &题解: 如果你看懂了Kruskal算法,那么这个也就很好懂了. 首先按边排序,之后找个连续的区间[L,R] 判断是否已经是生成树,如果是,更新答案就好. 判断是否为生成…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly,…
题意: 给出图的边和点数,要求最小生成树的代价,注:有些点之间是不可达的,也就是可能有多个连通图.比如4个点,2条边:1-2,3-4. 思路: 如果不能连通所有的点,就输出‘?’.之前以为每个点只要有边连着就一定能生成树,其实还可以是每个点虽然有边可达,但是给的其实是两个图,比如上例.其他按照常规Prim. #include <bits/stdc++.h> using namespace std; ; const int mod=0x7f7f7f7f; int v[N][N]; //权 int…
Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do some research on Spanning Tree. So Coach Pang decides to solve the following problem: Consi…
Abandoned country 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the roads need to be re-built. There are m(m≤1000000) ro…