HDU 5002 Tree】的更多相关文章

Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a…
Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93850#problem/F Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the w…
题意: 一棵树  支持删边加边.路径权值加值.路径权值改值.路径求第二大的数字和其个数 思路: LCT的第二题  题意已经把功能都告诉了  比較裸 要注意的是权值加值和改值两个操作的标记下放问题  要先down改值  再down加值 对于路径的操作通过mroot变换树的形态再access拿出路径比較方便  不要像我上一篇一样搞lca 代码: #include<cstdio> #include<iostream> #include<cstring> #include<…
Tree Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 920    Accepted Submission(s): 388 Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is a…
hdu 5909 Tree Cutting 题意:一颗无根树,每个点有权值,连通子树的权值为异或和,求异或和为[0,m)的方案数 \(f[i][j]\)表示子树i中经过i的连通子树异或和为j的方案数 转移类似背包,可以用fwt加速 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long lon…
HDU 5044 Tree field=problem&key=2014+ACM%2FICPC+Asia+Regional+Shanghai+Online&source=1&searchmode=source" target="_blank" style="">题目链接 就简单的树链剖分,只是坑要加输入外挂,还要手动扩栈 代码: #include <cstdio> #include <cstring>…
[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的…
Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Total Submission(s): 1643    Accepted Submission(s): 461 Problem Description   Zero and One are good friends who always have fun with each other. This time, t…
Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Description Zero and One are good friends who always have fun with each other. This time, they decide to do something on a tree which is a kind of graph…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem DescriptionConsider a un-rooted tree T which is not the biological significance of tree or plant, but a tre…
Tree Cutting 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5909 Description Byteasar has a tree T with n vertices conveniently labeled with 1,2,...,n. Each vertex of the tree has an integer value vi. The value of a non-empty tree T is equal to v1⊕v…
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 539064-bit integer IO format: %I64d      Java class name: Main   Given a rooted tree(node 1 is the root) with n nodes. The ithnode has a positive value vi…
传送门 Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Problem Description   Zero and One are good friends who always have fun with each other. This time, they decide to do something on a tree which is a kind…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形dp, 对于每条链u,v,w,我们只在lca(u,v)的顶点上处理它 让dp[i]表示以i为根的指数的最大值,sum[i]表示dp[vi]的和(vi为i的儿子们) 则i点有两种决策,一种是不选以i为lca的链,则dp[i]=sum[i]. 另一种是选一条以i为lca的链,那么有转移方程:dp[i]=…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4757 题意:给出一棵树,节点有权值.每次询问x到y的路径上与z抑或的最大值. 思路:可持久化trie. struct Node { int c[2],cnt; }; Node a[2000005]; int cnt; int newNode() { cnt++; a[cnt].c[0]=a[cnt].c[1]=a[cnt].cnt=0; return cnt; } struct node { int…
tree 把每条边权是1的边断开,发现每个点离他最近的点个数就是他所在的连通块大小. 开一个并查集,每次读到边权是0的边就合并.最后Ans​i​​=size[findset(i)],size表示每个并查集根的size Ans_i=size[findset(i)],sizeAns​i​​=size[findset(i)],size表示每个并查集根的sizesize. #include<cstdio> #include<cstring> #include<algorithm>…
Problem Description There is a tree(the tree is a connected graph which contains n points and n−1 edges),the points are labeled from 1 to n,which edge has a weight from 0 to 1,for every point i∈[1,n],you should find the number of the points which are…
Problem Description         A binary tree is a finite set of vertices that is either empty or consists of a root r and two disjoint binary trees called the left and right subtrees. There are three most important ways in which the vertices of a binary…
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3340    Accepted Submission(s): 1500 Problem Description A binary tree is a finite set of vertices that is either empty or…
Problem Description   Coco has a tree, whose vertices are conveniently labeled by 1,2,…,n.There are m chain on the tree, Each chain has a certain weight. Coco would like to pick out some chains any two of which do not share common vertices.Find out t…
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented by an integer, where the color of node i is ci. The path between each two different nodes is unique, of which we define the value as the number of di…
Binary Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 251    Accepted Submission(s): 143 Special Judge Problem Description The Old Frog King lives on the root of an infinite tree. Accordi…
http://acm.hdu.edu.cn/showproblem.php?pid=6394 题意 给出一棵树,然后每个节点有一个权值,代表这个点可以往上面跳多远,问最少需要多少次可以跳出这颗树 分析 先dfs一次得到dfs序,然后按dfs序分块.倍增计算从某点跳x到哪个点,用cn保存它跳出这一块需要的次数,ne保存跳出这块会去的点.然后块内就暴力修改了.复杂度nsqrt(n); #include <iostream> #include <cstdio> #include <…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=6394 思路:用dfs序处理下树,在用分块,我们只需要维护当前这个点要跳出这个块需要的步数和他跳出这个块去到的下一个点的下标,这样更新和询问的复杂度就降到了sqrt(n),查询树上的点的时候我们可以用倍增来降时间复杂度,这样处理下就不会超时了,. 介绍下代码主要数组的作用方便看懂代码:l[i] : 当前块的左边界 r[i]:当前块的右边界 num[i]: 当前点需要多少步跳出这个块 pre[i]: 这个…
http://acm.hdu.edu.cn/showproblem.php?pid=4757 题意: 给出一棵树,每个结点有一个权值,现在有多个询问,每次询问包含x,y,z三个数,求出在x到y的路径上与z最大的异或值. 思路: 看着别人的代码做完这道题目之后觉得这题和主席树求第k小是异曲同工的,主席树求第k小是对每个数建立一棵线段树,也就是说第i棵线段树记录的是区间[1,i]之间的数,这样的话[l,r]这个区间内的数就在第l棵线段树和第r棵线段树之间. 回到这题上来,这题也是要在一个范围之内寻找…
http://acm.hdu.edu.cn/showproblem.php?pid=4757 给出一棵树,每个节点有权值,每次查询节点 (u,v) 以及 val,问 u 到 v 路径上的某个节点与 val 异或最大的值是多少. 和可持久化线段树差不多,看代码吧. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1710 解题思路:可以由先序和中序的性质得到 : 先序的第一个借点肯定是当前子树的根结点, 那么在 中序中找到这个结点, 则这个结点左边的节点属于左子树, 右边的属于右子树.然后递归遍历就可以了. 样例: 9 1 2 4 7 3 5 8 9 6 4 7 2 1 8 5 9 3 6   7 4 2 8 9 5 6 3 1 如图:   因此,用深搜就能轻松解决了,注意DFS中的变量,以及向清楚DFS的条件…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5909 点分治的话,每次要做一次树形DP:但时间应该是 siz*m2 的.可以用 FWT 变成 siz*mlogm ,但这里写的是把树变成序列来 DP 的方法,应该是 nlogn*m 的. 树上的一个点,如果选,就可以选它的孩子,所以它向它的第一个孩子连边:如果不选,就会跳到它的下一个兄弟或者是父亲的下一个兄弟之类的,向那边连一条边. 做出树的 dfs 序,把边都连在 dfs 序上:其实那个第一条边一定连…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5909 [题目大意] 给出一棵树,其每棵连通子树的价值为其点权的xor和, 问有多少连通子树的价值为1~m [题解] 首先定1为根,转有根树,我们在树的每个节点保存一个权值数组, 表示与其连通的子树的权值,当一个子树并入其父节点时, dp[x][i]=dp[x][i]+dp[x][j]*dp[y][k](j^k==i),我们发现这是一个位运算卷积式子, 所以树上转移可以用fwt加速. [代码] #…
题意:询问树上结点x到结点y路上上的权值异或z的最大值. 任意结点权值 ≤ 2^16,可以想到用字典树. 但是因为是询问某条路径上的字典树,将字典树可持续化,字典树上的结点保存在这条路径上的二进制数. 按照dfs序建树,结点u的字典树表示u到根结点路径上的字典树. 如果两个结点u和v,在同一条通往根结点的路径上,将会满足可减性. 因此只需要知道u.v.lca和fa[lca]四个结点的字典树就可以回答了. /*********************************************…