Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 200000/200000 K (Java/Others)Total Submission(s): 2925    Accepted Submission(s): 894 Problem Description Nowadays, people have many ways to save money on accommodation w…
题目链接: Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 200000/200000 K (Java/Others) Problem Description   Nowadays, people have many ways to save money on accommodation when they are on vacation.One of these ways is e…
[HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树的最大权值和(选的链都在i的子树中) 设sum[x]表示x的儿子的dp值和,即\(\sum _{y \in \mathrm{son}(x)} dp[y]\) 1.不选两端点lca为x的链,dp[x]=sum[x] 2.选两端点lca为x的链,则dp[x]=max{链的权值+链上节点的所有子节点dp的…
Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 200000/200000 K (Java/Others)Total Submission(s): 2009    Accepted Submission(s): 558 Problem Description Nowadays, people have many ways to save money on accommodation w…
Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14550   Accepted: 6173 Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a collection of one or m…
Godfather Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6121   Accepted: 2164 Description Last years Chicago was full of gangster fights and strange murders. The chief of the police got really tired of all these crimes, and decided to…
题目链接:https://cn.vjudge.net/contest/277955#problem/D 题目大意:求树的重心(树的重心指的是树上的某一个点,删掉之后形成的多棵树中节点数最大值最小). 具体思路:对于每一个点,我们求出以当前的点为根的根数的节点个数, 然后在求树的重心的时候,一共有两种情况,一种树去除该点后这个点的子节点中存在所求的最大值,还有一种情况是这个点往上会求出最大值,往上的最大值就是(n-dp[rt][0]). AC代码: #include<iostream> #inc…
Tree Cutting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4834   Accepted: 2958 Description After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible…
题意:就是裸的求树的重心. #include<cstring> #include<algorithm> #include<cmath> #include<cstdio> #include<iostream> #define N 20007 #define inf 100000007 using namespace std; int n,id,mnum; int siz[N]; ],rea[N*]; void add(int u,int v) {…
题意:给n个点,每个点有一个人,有n-1条有权值的边,求所有人不在原来位置所移动的距离的和最大值. 析:对于每边条,我们可以这么考虑,它的左右两边的点数最少的就是要加的数目,因为最好的情况就是左边到右边,右边到左边,然后用dfs就可以解决了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <…