题目意思: 给出你一颗带点权的树,dist(i, j)的值为节点i到j的距离乘上节点j的权值,让你任意找一个节点v,使得dist(v, i) (1 < i < n)的和最大.输出最大的值. 题目分析: 首先如果你可以熟悉的使用树形dp的话 , 可以很快的意识的先从1号点开始dfs一遍,然后通过一些奇怪的方式,再dfs一遍得到其他点的贡献.无所以我们需要找到一个递推式是满足我选择其他号码为根时候,可以很快的得到答案 . 现在假设有两个节点v , fa ; v 是 fa 的儿子节点 , 根据dp的…
题目大意: 给定一棵树 每个点都有点权 每条边的长度都为1 树上一点到另一点的距离为最短路经过的边的长度总和 树上一点到另一点的花费为距离乘另一点的点权 选定一点出发 使得其他点到该点的花费总和是最大的 先dfs一遍 获得 s[u] 为u点往下的点权总和(包括u点) 由其子节点v及其本身权值可得 s[u]=s[v]+w[u] 获得 dp[u] 为u点出发往下的花费总和(u点出发的花费不需要包括u点) 由其子节点v的dp[v]及s[v]可得 dp[u]=dp[v]+s[v] 再深搜一遍树形dp 获…
题目链接:传送门 思路: 题意说用线段的相交作为边,来构造树,所以不存在大于等于3个的线段两两相交,否则会构成环.因而构造出的树中,每个点最多只会与2个度大于1的节点相邻. 不妨把1设为树根,用degu表示原树中节点u的度,ans表示答案. 用fu表示:假设以u为根的子树,已经有一条边连向了一个度大于1的点时,所能构成的最大的“子树的子树”的大小,则有: fu = 1,if degu=1.叶子本身就是一个点,大小为1. fu = max{v是u的子节点 | fv} + degu-2 + 1.所有…
题意 给定一颗树,求这个树的最大子树,且这个子树是一个good-tree. good-tree的定义是:每个节点可以表示成一个数值区间,而树上的边表示两个点表示的数值区间相交. 题解 通过分析可以发现,这个子树是这个树的一条链,然后允许这条链上的点带上直接连接的点. 然后就转化为树上求最长链的DP问题. // #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragma GCC optimize(4) #include <bits/s…
传送门:http://codeforces.com/contest/1092/problem/F F. Tree with Maximum Cost time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree consisting exactly of nn vertices. Tree is a…
题:https://codeforces.com/contest/1249/problem/F 题意:给一颗树,边权为1,节点有点权,问取到一个点集,俩俩之间路径超过k,是点权和最大 思路:贪心地取点,先将点按照深度经行排序,每一次,取一个点权大于0的点,然后对于这个点bfs出去的路径小于k的点减去当前点的a[u],然后将a[i]加入到ans中 #include<bits/stdc++.h> using namespace std; #define fo(i,a,b) for(int i=a;…
D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponso…
Rebuilding RoadsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 8589 Accepted: 3854Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The cows d…
题意: There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a number defined as the distance…
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the route. There are N houses and N - 1 roads in his village. Each road connects two houses,…