【BZOJ1468】Tree [点分治]】的更多相关文章

Description 给你一棵TREE,以及这棵树上边的距离.问有多少对点它们两者间的距离小于等于K Input N(n<=40000) 接下来n-1行边描述管道,按照题目中写的输入 接下来是k Output 一行,有多少对点之间的距离小于等于k Sample Input 7 1 6 13 6 3 9 3 5 7 4 1 3 2 4 20 4 7 2 10 Sample Output 5 Solution 点分治模板 Code #include<iostream> #include&l…
POJ1741 Tree + BZOJ1468 Tree Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid i…
1468: Tree Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1025  Solved: 534[Submit][Status][Discuss] Description 给你一棵TREE,以及这棵树上边的距离.问有多少对点它们两者间的距离小于等于K Input N(n<=40000) 接下来n-1行边描述管道,按照题目中写的输入 接下来是k Output 一行,有多少对点之间的距离小于等于k Sample Input 7 1 6 13 6…
Tree Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description 给你一棵TREE,以及这棵树上边的距离,问有多少对点它们两者间的距离小于等于K. Input 第一行一个n,接下来n-1行边描述管道,按照题目中写的输入,接下来是一个k. Output 仅包括一个整数,表示有多少对点之间的距离小于等于k. Sample Input 7 1 6 13 6 3 9 3 5 7 4 1 3 2 4 20 4…
可以说是点分治第一题,之前那道的点分治只是模模糊糊,做完这道题感觉清楚了很多,点分治可以理解为每次树的重心(这样会把数分为若干棵子树,子树大小为log级别),然后统计包含重心的整个子树的值减去各个子树的值,这样算出的就是与这个重心有关的情况的答案,比如这道题,求路径,那么就考虑在重心所在的子树中所有的路径减去不过重心的路径就是过重心的路径了.之前重心没找对...poj时间卡的紧就T了.. #include <iostream> #include <algorithm> #inclu…
点分治的入门练习. 题目链接 BZOJ的链接(权限题) 关于点分治的思想我就不再重复了,这里重点说一下如何判重. 我们来看上图,假设我们去除了1节点,求出d[2]=1,d[3]=d[4]=2 假设k为5,这样我们会认为节点(2,3)(2,4)(3,4)的距离小于k,从而累计到答案中 但是我们以2为root做点分治时还会将(3,4)计算一遍,这样就重复了 所以我们每一次计算答案时还要讲所有多余情况减去,最终答案才是我们要求的答案 不难发现多余情况是在root节点与root子节点重复统计的,我们在点…
同poj1741. 换了个更快的姿势,不会重复统计然后再减掉什么的啦~ #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define MAXN 40001 #define INF 2147483647 typedef pair<int,int> Point; int n,K,ans; int v[MAXN<<1],w[MAXN<<…
最经典的点分治题目,在递归子树的时候减去在算父亲时的不合法方案. #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> #include<cmath> #define ll long long #define N 40005 using namespace std; struct Node{ int to,ne…
D Tree Problem Description   There is a skyscraping tree standing on the playground of Nanjing University of Science and Technology. On each branch of the tree is an integer (The tree can be treated as a connected graph with N vertices, while each br…
Tree     Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u…