LCA
ffutop
这个作者很懒,什么都没留下…
展开
-
HDU 6031 Innumerable Ancestors (LCA)
There is a tree having n nodes, labeled from 1 to n. The root of the tree is always 1, and the depth of a node p is the number of nodes on the shortest path between node p and the root. In computer sc原创 2017-05-11 08:56:32 · 700 阅读 · 0 评论 -
Codeforces Gym 101173 H. Hangar Hurdles (LCA + 并查集)
题意在 . 和 # 所组合成的矩形 N×NN\times N 地图。kijk_{ij} 表示以 (i, j) 为中心的最大正方形(正方形范围内全是 . )的边长为 k 。问对于每个询问从 (sx, sy) 到 (ex, ey) 的过程中最大的正方形边长 k ,使得满足在每一时刻正方形所包含的区域内均不存在 # 同时不会越界。解题思路首先通过洪泛算法求解每个点的 k 。具体过程见 flood_fill原创 2017-07-01 16:34:19 · 957 阅读 · 0 评论 -
Codeforces Gym 101142 G. Gangsters in Central City (最近公共祖先)
题意树的根节点为水源,编号为 1 。给定编号为 2, 3, 4, …, n 的点的父节点。已知所有叶节点都是房子。有 q 个操作,每个操作可以是下列两者之一:+ v ,表示编号为 v 的房子被歹徒占领。- v ,表示歹徒退出编号为 v 的房子。初始所有房子都没有歹徒。对于每次变化后,要求删除最少的边,使得所有有歹徒的房子均无法与水源连通;同时,在此基础上要求受影响的普通房子数量最少。解题思路令原创 2017-06-27 13:21:32 · 765 阅读 · 0 评论 -
Codeforces 838B. Diverging Directions (LCA+线段树, IndiaHacks 2nd Elimination 2017 )
ProblemYou are given a directed weighted graph with n nodes and 2*n* - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2*n* - 2. The graph’s edges can be split into tw原创 2017-08-08 09:44:30 · 557 阅读 · 0 评论 -
HDU 6065 RXD, tree and sequence (LCA, 2017 Multi-Univ Training Contest 3)
Problem有根树 T 有 N 个节点,根节点标号为 1 ,深度为 1 。特定序列 P 有 N 个不同数字 (1~N) 。定义每个块的深度为块中所有点的最近公共祖先的深度。求将 P 序列划分成 K 个连续的块,使得 K 块的深度和最小,问最小深度和 ?Limit1≤k≤n≤3×1051\le k \le n \le 3\times 10^5n×k≤3×105n\times k \le 3\time原创 2017-08-02 17:05:13 · 581 阅读 · 0 评论 -
HDU 6074 Phone Call (LCA+并查集, 2017 Multi-Univ Training Contest 4)
ProblemThere are n houses in Bytetown, labeled by 1,2,…,n. In each house, there is a person living here. Little Q lives in house 1. There are n−1 bidirectional streets connecting these houses, forming原创 2017-08-05 14:36:45 · 1252 阅读 · 0 评论 -
HDU 6203 ping ping ping (LCA + 树状数组, 2017 ACM/ICPC Asia Regional Shenyang Online)
Problemn+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连通。问无法通行的点最少有多少个。Idea根据所给的树(任意点为根)预处理出每个点的前序 DFS 序和后序 DFS 序(需统一标号),及点的深度。根据 p 组 U V 处理每组两点的 LCA 。压入优先队列(LCA 深度大的点优先出队)。对于出队的 U V 及其对应的 LCA ,判断点 U原创 2017-09-11 09:19:30 · 1598 阅读 · 0 评论