ARC121E Directed Tree】的更多相关文章

令$b_{a_{i}}=i$,那么问题即要求$i$不是$b_{i}$的祖先,也即$b_{i}$不严格在$i$的子树中 显然$a_{i}$和$b_{i}$一一对应,因此我们不妨统计$b_{i}$的个数 考虑容斥,令$f(S)$为$\forall i\in S,b_{i}$严格在$i$子树中的排列数,根据容斥答案即$\sum_{S\subseteq [1,n]}(-1)^{|S|}f(S)$ 关于$f(S)$,可以从底往上依次确定$i\in S$的$b_{i}$,方案数即$\prod_{i\in S…
四边形优化DP Tree Construction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 868    Accepted Submission(s): 470 Problem Description Consider a two-dimensional space with a set of points (xi, yi) t…
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数组,方便查询,不方便修改,以bfs序建立树状数组,方便修改,不方便查询. 在计算子树权重的时候发现,如果我能算出 所有层 属于这棵子树的  点数*对应层需要加上的val,那么就得到了这棵树的总权重.但是显然暴力统计点数会超时,于是我们把用一个分块的想法,对于一层来说,如果这层的总点数小于块的大小,就…
Problem Description Consider a two-dimensional space with a set of points (xi, yi) that satisfy xi < xj and yi > yj for all i < j. We want to have them all connected by a directed tree whose edges go toward either right (x positive) or upward (y…
Description The company \(X\) has \(n\) employees numbered from \(1\) through \(n\). Each employee \(u\) has a direct boss \(p_u\) \((1 \le p_u \le n)\), except for the employee \(1\) who has no boss. It is guaranteed, that values \(p_i\) form a tree…
In this article I will talk in depth about the Angular 2 change detection system. HIGH-LEVEL OVERVIEW An Angular 2 application is a tree of components. An Angular 2 application is a reactive system, with change detection being the core of it. Every c…
Home » Practice(Hard) » Dynamic Trees and Queries Problem Code: ANUDTQSubmit https://www.codechef.com/problems/ANUDTQ Tweet   All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. Given a directed tr…
F. Economic Difficulties An electrical grid in Berland palaces consists of 2 grids: main and reserve. Wires in palaces are made of expensive material, so selling some of them would be a good idea! Each grid (main and reserve) has a head node (its num…
模板题:在有向图中,对每一个点求以其为根的最小(外向)生成树 (当图是强连通时)可以使用朱刘算法,算法过程如下: 1.对每一个节点,选择指向该点的边权最小的边,即得到一张子图 2.任选这张子图的一个简单环,并对这个环执行以下操作-- (1)对于环上的边$(u,v)$​,将所有以$v$​为终点的边边权减去$(u,v)$​​的边权 (2)新建一个点为将环上所有点合并后的结果,并删除新点的自环 3.重复此过程,直至仅剩下一个点 (不难证明第1步中每一个点入度都非0,第2步中一定存在一个环) 在此过程中…
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22720    Accepted Submission(s): 5168 Problem Description A tree is a well-known data structure that is either empty (null, void, no…