![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dsu on the tree
Clove_unique
All that you have lost can be won back bit by bit as long as you wish for it.
展开
-
[Codeforces246E]Blood Cousins Return(dsu on the tree+set)
题目描述传送门 题意:一棵树,每一个点有一个颜色(字符串),每一次询问以某一个点为根的子树中与其距离为k的点有多少种颜色。题解dsu on the tree… 关键是这道题要统计每一个深度出现的颜色的个数,于是每一个深度挂一个set stl真tm省事。代码#include<algorithm>#include<iostream>#include<cstring>#include<cstd原创 2017-03-08 10:21:10 · 612 阅读 · 0 评论 -
[Codeforces375D]Tree and Queries(dsu on the tree+bit)
题目描述传送门 题意:一棵树,每个点有一个颜色,每一次询问以x为根的子树中至少出现k次的颜色有多少种题解dsu on the tree… 记每一个颜色出现了多少次,再记出现多少次的颜色有多少个 因为是至少出现k次,挂一个bit就行了 注意bit更新的时候每一次都到最大值代码#include<algorithm>#include<iostream>#include<cstring>#in原创 2017-03-08 09:02:42 · 783 阅读 · 0 评论 -
[Codeforces741D]Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(dsu on the tree)
题目描述传送门题解一道细节比较多的dsu on the tree 首先某一个子树中的路径可以分为经过根的和不经过根的,不经过根的可以通过儿子更新过来,所以对于每一棵子树只统计经过根的路径。 经过根的路径又可以分成两种,第一种是到根就结束的,也就是说是根到它子树里某一个点的一条链,这个可以在dfs的时候统计。 第二种是路径的两个端点分别在根的两个儿子的子树里。令s(i)表示1到i的路径的状态,状原创 2017-03-08 08:05:49 · 940 阅读 · 0 评论 -
[Codeforces208E]Blood Cousins(dsu on the tree+倍增)
题目描述传送门 题意:给出一棵家谱树,定义向上走k步到达的节点为该点的k-ancestor。每次询问与v同P-ancestor的节点有多少个。题解题目可以转化为在v的P-ancestor的子树里和v同一深度的有多少个点 用dsu on the tree搞一搞。。 倍增求出v的P-ancestor,然后对于每一个询问加一个链表,一遍dfs就行了。 注意这是一个森林 时间复杂度O(nlogn)原创 2017-03-07 19:30:21 · 845 阅读 · 0 评论 -
[Codeforces570D]Tree Requests(dsu on the tree)
题目描述传送门 题意:一棵树,每一个点有一个字符,给出若干询问,每一次询问以某个点为根的子树中深度为x的点能否组成一个回文串。题解用dsu on the tree搞一下。。 如果可以组成一个回文串的话出现次数为奇数的字符至多有一个 记录一下深度为i的点中字符为j的个数,然后对于每一个点的询问搞一个链表查询就可以了 时间复杂度O(nlogn)O(nlogn)代码#include<algorit原创 2017-03-07 19:07:26 · 529 阅读 · 0 评论 -
[Codeforces600E]Lomsat gelral(dsu on the tree)
题目描述传送门 题意:一棵树,每一个点有一个颜色,统计以每一个节点为根的子树中出现次数最多的颜色的编号和。题解学习了一下dsu on the tree,安利一下Yveh的良心博客:http://blog.csdn.net/qaq__qaq/article/details/53455462 算法的大致过程: 首先将树轻重链剖分,在dfs的过程中先dfs轻儿子,再dfs重儿子。 假设某一个点的儿原创 2017-03-07 18:37:58 · 1295 阅读 · 0 评论