题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5723 n个村庄m条双向路,从中要选一些路重建使得村庄直接或间接相连且花费最少,这个问题就是很明显的求最小生成树,由于边权各不相同,所以最小生成树唯一. 然后,在这个最小生成树的基础上,求各个路径的最小期望和(推导出 期望 = 所有村庄中任意两个村庄距离之和 / 村庄对数). 最小生成树很好求(边权从小到大,并查集一下就好了). 然后求以上基础村庄中任意两个村庄距离之和,只要求每条边乘上每条边出现的次…
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…
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…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3006    Accepted Submission(s): 346 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
题目链接:hdu 5723 Abandoned country 题目大意:N个点,M条边:先构成一棵最小生成树,然后这个最小生成树上求任意两点之间的路径长度和,并求期望 /************************************************************** Problem:hdu 5723 User: youmi Language: C++ Result: Accepted Time:2932MS Memory:22396K solution:首先注意到任…
HDU 5723 Abandoned country(落后渣国) Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since abandoned for a long time, the r…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5723 Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 7573    Accepted Submission(s): 1850 Problem Description An abandoned country…
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…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1756    Accepted Submission(s): 475 Problem Description An abandoned country has n(n≤100000) villages which are numbered from 1…
Problem DescriptionAn 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) roads to be re-built, the length of each road is wi(wi≤1000000). G…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5723 [题目大意] n座城市,m条路径,求解: 1.最短的路径和,使得n座城市之间直接或者间接连通 2.在路径和最短的情况下,求出任意两个城市之间的期望距离 [题解] 对于问题1,只需求出该图的最小生成树,边权和即答案,由于边权值唯一,因此不存在最小生成树多解的情况. 对于问题2,期望的通常求法为(任意两点之间的路径和)/(点对数) 那么问题就转化为任意两点间距离和的问题,我们按边考虑,对于每条…
http://acm.split.hdu.edu.cn/showproblem.php?pid=5723 题意:给出一个无向图,每条路都有一个代价,求出把所有城市连通的最小代价.在此基础上,国王会从这里面随机挑出两个城市作为起点和终点,求出国王要走的路的期望值. 思路: 第一问很简单,最小生成树计算一下即可. 对于第二问,在新图的基础上,考虑每条边所能给出的贡献值.假设这条边两个的点数分别为x和y,那么这条边总的贡献次数就是x*y,贡献值为x*y*w.求两边的点数dfs即可. #include<…
题目说每条边权值都不一样,说明最小生成树是唯一的,不存在最小期望这一说. 然后就是先求出最小生成树,随便确定一个根节点,计算出每个点的子树有多少节点,记为c[x]. 指向x的这条边被统计的次数为c[x]*(n-c[x]).然后基本就可以算出答案了. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<…
#include<bits/stdc++.h> using namespace std; struct node{ int u, v, w, nex; bool gone; node(){} node(int a,int b,int c){ u = a;v = b;w = c;gone = false; } bool operator <(const node&a)const{ return w < a.w; } }; ; ; node Gra[maxE]; int dp[…
http://acm.hdu.edu.cn/showproblem.php?pid=5723 Abandoned country Problem 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…
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) roads to be re-built, the length of each road is wi(wi≤1000000). Guarante…
Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem 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…
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. /* HDU 1241 Oil Deposits --- 入门DFS */ #include <cstdio> int m, n; //n行m列 ][]; /* 将和i,j同处于一个连通块的字符标记出来 */ void dfs(int i, int j){ || j < || i >=…
HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u   Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large r…
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of the Bone [从零开始DFS(1)] -DFS四向搜索/奇偶剪枝 HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] -DFS四向搜索变种 HDOJ(HDU).1016 Prime Ring Problem (DF…
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tempter of the Bone [从零开始DFS(1)] -DFS四向搜索/奇偶剪枝 HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] -DFS四向搜索变种 HDOJ(HDU).1016 Prime Ring Problem (…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5723 题意:求最小生成树,并且求这棵最小生成树上所有边走过次数的期望. 走过次数的期望=Σ边被走过次数*边权/(n*(n-1)/2) 求边被走过的次数,相当于关心这个边的两侧分别有多少点,走的次数就是两边的点数的乘积这个很好理解.可以从边的一侧开始dfs,找到这个边的一侧点数x,由于最小生成树是联通的,那么边的另一侧点数一定是n-x.所以这条边的贡献是(n-x)*x*w. #include <bit…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 Problem Description For a tree, which nodes and edges are all weighted, the ratio of it is calculated according to the following equation. Given a complete graph of n nodes with all nodes and edges…
想到枚举m个点,然后求最小生成树,ratio即为最小生成树的边权/总的点权.但是怎么枚举这m个点,实在不会.网上查了一下大牛们的解法,用dfs枚举,没想到dfs还有这么个作用. 参考链接:http://blog.csdn.net/xingyeyongheng/article/details/9373271 #include <stdio.h> #include <string.h> #include <set> #include <vector> #incl…
Minimal Ratio Tree Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 12   Accepted Submission(s) : 7 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description For a tree, which n…
Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] For a tree, which nodes and edges are all weighted, the ratio of it is calculated according to the following equation.Given a…
题意:给定一个 n 个点和相应的权值,要求你用 n-1 条边连接起来,其中一条边是魔法边,不用任何费用,其他的边是长度,求该魔法边的两端的权值与其他边费用的尽量大. 析:先求出最小生成树,然后再枚举每一条边,求出最大值,任意两点之间的距离可以通过预处理来解决,最小生成树时,要用prime算法,要不然可能会超时. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
题意:求最小生成树,和任意两个点之间距离的期望 官方题解: 最后求两遍点的积的时候,还是要判断父子关系. 注意 long long #include <bits/stdc++.h> using namespace std; typedef long long LL; +; int father[maxn]; int Find_Set(int x) { if(x!=father[x]) father[x] = Find_Set(father[x]); return father[x]; } st…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4126 题意:给出一幅3000个点的图,有10000次操作: 求将某条边的权值变大后的最小生成树,最后输出10000次操作得到的最小生成树权值的平均值. 分析: 对于每次询问, 都是将a,b之间的边增加到c, 会出现 两种情况: 1. 如果边权增加的那条边原先就不在最小生成树中,那么这时候的最小生成树的值不变 2. 如果该边在原最小生成树中,那么这时候将增加的边从原最小生成树中去掉,这时候生成树就被分…
题目链接:hdu_5723_Abandoned country 题意: 让你求最小生成树的花费,然后求任给两点的期望路程 题解: 最小生成树大家都会求,Kruskal这里要改改,因为后面要求任意两点的期望路程,我们这里Kruskal 记录下最小生成树的边,然后通过DFS把树建出来,最后找每条边经过了多少次,然后乘上对应的组合,比如样列,第一条边权为1的边,这条边左边只有一个节点,右边有3个节点,那么这条边就会经过3次,所以这条边的贡献就是1(左边点个数)*3(右边点个数)*1(边权),依次类推,…