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,…
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14197 Accepted Submission(s): 3170 Problem Description A tree is a well-known data structure that is either empty (null, void, n…
Big binary tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 597 Accepted Submission(s): 207 Problem Description You are given a complete binary tree with n nodes. The root node is numbere…
http://acm.uestc.edu.cn/#/problem/show/32 树上战争(Battle on the tree) Time Limit: 12000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status 给一棵树,如果树上的某个节点被某个人占据,则它的所有儿子都被占据,lxh和pfz初始时分别站在两个节点上,谁当前所在的点被另一个人占据,他就输了比赛,问谁能获胜. In…
Design an algorithm to encode an N-ary tree into a binary tree and decode the binary tree to get the original N-ary tree. An N-ary tree is a rooted tree in which each node has no more than N children. Similarly, a binary tree is a rooted tree in whic…
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…
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…
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…
称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 这个差点儿相同,就是当前行的状态对上一行有影响.对上上一行也有影响.所以 定义状态:dp[i][now][up]表示在第 i 行状态为now .上一行状态为 up 时的方案数. 然后转移方程:dp[i][now][up] = sum ( dp[i-1][up][uup] ) 前提是合法 合法性的推断…
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 967 Accepted Submission(s): 308 Problem Description CRB has a tree, whose vertices are labeled by 1, 2, …, N. They are connected b…
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the nod…
Description Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Example Given a binary tree as follow: 1 / \ 2 3 / \ 4 5 The minimum depth is …
题目链接[http://www.spoj.com/problems/QTREE/] 题意:给出一个包含N(N<=10000)节点的无根树,有多次询问,询问的方式有两种1.DIST a b 求a->b之间的距离.2.KTH a b k 求a->b链上的第k个节点是谁,.如果输入DONE,结束询问. 思路:首先想到用倍增法可以解决第一种询问,只需要在DFS时候维护一个dis[i](表示i节点到根节点之间的距离,因为是无根树,我们定义节点1为根),dis(a->b)=dis[a]+di…
算是板子,把值离散化,每个点到跟上做主席树,然后查询的时候主席树上用u+v-lca-fa[lca]的值二分 #include<iostream> #include<cstdio> #include<map> #include<algorithm> using namespace std; const int N=100005; int n,m,h[N],cnt,tot,la,a[N],ha[N],b[N],has,f[N][30],rt[N],ind,po[…
早先以为莫队是个顶有用的东西,不过好像树上莫队(不带修)被dsu碾压? dsu one tree起源 dsu on tree是有人在cf上blog上首发的一种基于轻重链剖分的算法,然后好像由因为这个人后来在cf上办了场比赛出了道dsu on tree的裸题由此出名? 这个是原博客地址:http://codeforces.com/blog/entry/44351 大概思想就是一种树上启发式合并,利用轻重链剖分把重复计算的答案利用起来,从而把时间复杂度控制在$O(n log n)$(不过不能修改).…
[题意]给定n个点的树,每条边有一个小写字母a~v,求每棵子树内的最长回文路径,回文路径定义为路径上所有字母存在一种排列为回文串.n<=5*10^5. [算法]dsu on tree [题解]这题经典套路就是按照22个字母个数的奇偶性压位,然后两段路径异或起来是0或1<<j就是合法路径. dsu的时候每个点统计其子树内经过这个点的路径,注意包括从子树到该点终止的和该点自身也要算. 那么类似点分治的方式,算完重儿子后处理一下根,然后就一棵一棵轻儿子子树和之前的子树状态桶数组统计然后加入.…
[题目]E. Lomsat gelral [题意]给定n个点的树,1为根,每个点有一种颜色ci,一种颜色占领一棵子树当且仅当子树内没有颜色的出现次数超过它,求n个答案——每棵子树的占领颜色的编号和Σci(一棵子树可能有多种占领颜色).1<=n,ci<=10^5. [算法]dsu on tree [题解]入门题,讲一下dsu on tree算法. 一.dsu on tree的适用范围:①子树询问,②支持数组上的快速信息加,③不带修.(注意不需要支持信息删除,只需要能清空信息) 如果写暴力的时候,…