HDU4358 Boring counting【dsu on tree】】的更多相关文章

Boring counting Problem Description In this problem we consider a rooted tree with N vertices. The vertices are numbered from 1 to N, and vertex 1 represents the root. There are integer weights on each vectice. Your task is to answer a list of querie…
Description 给定一棵 \(n\) 个节点的树,每条边上有一个字符,字符集大小 \(22\),求每个节点的子树内最长的简单路径使得路径上的字符经过重排后构成回文串. Limitation \(1~\leq~n~\leq~500000,~\text{字符集}~=~['a',~'v']\) Solution 考虑一条路径能构成回文串当且仅当路径上的字符出现奇数次的至多为一个.由于字符集大小很小,我们考虑状态压缩,即每个字符对应二进制位上的一个 \(1\).考虑从每个点出发向下走,显然链长越…
Problem E. Split The Tree Problem Description You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wi We define the weight of a tree as the number of different vertex value in the tree. If we delete one edge in the tree,…
Problem E. TeaTree Problem Description Recently, TeaTree acquire new knoledge gcd (Greatest Common Divisor), now she want to test you. As we know, TeaTree is a tree and her root is node 1, she have n nodes and n-1 edge, for each node i, it has it's v…
题意: 一棵树,询问一个子树内出现次数$≥k$的颜色有几种 强制在线见上一道 用莫队不知道比分块高到哪里去了,超好写不用调7倍速度!!! 可以用分块维护出现次数这个权值,实现$O(1)-O(\sqrt{N})$修改查询 [update 2017-03-22]还可以用dsu on tree做,并不想再写了... #include <iostream> #include <cstdio> #include <algorithm> #include <cstring&g…
Query on A Tree Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to practise it at once. Monkey A gave a v…
题目: Invert Binary Tree Total Accepted: 20346 Total Submissions: 57084My Submissions Question Solution  Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was inspired by this original tweet by Max Howell:…
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 代码: /** * Definition for a bina…
http://blog.csdn.net/c20182030/article/details/52327948 1388:Lake Counting 总时间限制:   1000ms   内存限制:   65536kB 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 1…
平衡的二叉树的定义都是递归的定义,所以,用递归来解决问题,还是挺容易的额. 本质上是递归的遍历二叉树. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,判定他是不是高度平衡的二叉树. 对于这个问题,每个节点的两个子树的深度不会相差超过1,那么这样的二叉树就是一个平衡的二叉树 +++++++++++++++++++++++++++++++++++++++++++++…