
LCA
csu_xiji
这个作者很懒,什么都没留下…
展开
-
SPOJ Count on a tree II 树上莫队
https://vjudge.net/problem/SPOJ-COT2题目大意:给一棵nnn个节点的数,每个节点有一种颜色,mmm个询问(u,v)(u,v)(u,v),你需要输出u、vu、vu、v这条链上的不同的颜色数目。思路:如果这道题是在区间内询问的,相信大家都能看出来是莫队。在树上怎么搞呢?树上莫队。通过欧拉序把链转换成区间,然后就可以做了。树上莫队的思想这里不想重复了,不懂的可以看下...原创 2020-04-08 01:53:14 · 228 阅读 · 0 评论 -
codeforces 1328E Tree Queries 思维 dfs序 LCA
https://vjudge.net/problem/CodeForces-1328E题目大意:给一棵树,根节点是111,mmm个询问,每次询问有lenlenlen个点,问能否找到一个点uuu,使得这lenlenlen个点要么在从uuu到根节点的路径上,要么距离这个路径的距离为111。思路:其实真的挺水的,当时居然没有想法,太菜了QAQQAQQAQ。首先做一波转换,令k[i]=fa[k[i]]...原创 2020-03-29 00:16:46 · 354 阅读 · 0 评论 -
codeforces 1304E 1-Trees and Queries LCA
https://vjudge.net/problem/CodeForces-1304E题目大意:给一棵树,qqq个询问(x,y,a,b,k)(x,y,a,b,k)(x,y,a,b,k),表示在给x、yx、yx、y加一条边的情况下,问是否存在一条从aaa到bbb的经过了kkk条边的路径,该路径可以多次经过同一个点、同一条边,但是起点必须是aaa,终点必须是bbb(有疑问的可看下样例)。思路...原创 2020-03-15 14:45:16 · 150 阅读 · 0 评论 -
洛谷P2245 星际导航 最小生成树+LCA求树链最大值
https://www.luogu.org/problem/P2245题目描述\text{sideman}sideman 做好了回到 \text{Gliese}Gliese 星球的硬件准备,但是 \text{sideman}sideman 的导航系统还没有完全设计好。为了方便起见,我们可以认为宇宙是一张有 NN 个顶点和 MM 条边的带权无向图,顶点表示各个星系,两个星系之间有边就表示两个星系...原创 2019-08-22 16:36:52 · 237 阅读 · 0 评论 -
HDU 6203 ping ping ping LCA+dfs序+树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=6203The structure of the computer room in Northeastern University is pretty miraculous. There are n servers, some servers connect to the gateway whose IP add...原创 2019-08-09 15:56:34 · 165 阅读 · 0 评论 -
Gym - 101808K Another Shortest Path Problem LCA+思维
http://codeforces.com/gym/101808/problem/KShortest path problems have always been a part of competitive programming, appearing in many contests all around the world. In order to keep that tradition, ...原创 2019-08-09 14:41:49 · 204 阅读 · 0 评论 -
HDU 3830 Checkers LCA+二分(很有想法的一道题)
http://acm.hdu.edu.cn/showproblem.php?pid=3830Little X, Little Y and Little Z are playing checkers when Little Y is annoyed. So he wants to make the chessboard much bigger. Although Little Z insists...转载 2019-08-06 14:39:39 · 165 阅读 · 0 评论 -
SPOJ QTREE2 - Query on a tree II LCA+思维
https://www.spoj.com/problems/QTREE2/en/You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. Each edge has an integer value assigned to it, re...原创 2019-08-08 12:15:06 · 135 阅读 · 0 评论 -
POJ 2763 Housewife Wind LCA+树状数组 dfs序
http://poj.org/problem?id=2763After their royal wedding, Jiajia and Wind hid away in XX Village, to enjoy their ordinary happy life. People in XX Village lived in beautiful huts. There are some pair...原创 2019-08-01 19:30:53 · 154 阅读 · 0 评论 -
POJ 2586 How far away ? LCA
http://acm.hdu.edu.cn/showproblem.php?pid=2586There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to...原创 2019-08-01 16:14:48 · 161 阅读 · 0 评论 -
POJ 1986 Distance Queries LCA
http://poj.org/problem?id=1986Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasona...原创 2019-08-01 16:13:51 · 165 阅读 · 0 评论 -
BZOJ 2243 染色 树链剖分+线段树
https://www.lydsy.com/JudgeOnline/problem.php?id=2243给定一棵有n个节点的无根树和m个操作,操作有2类:1、将节点a到节点b路径上所有点都染成颜色c;2、询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“112221”由3段组成:“11”、“222”和“1”。请你写一个程序依次完成这m个操作。Inpu...原创 2019-08-01 13:25:50 · 218 阅读 · 0 评论 -
LCA(最近公共祖先) 模板
对LCA及算法的介绍:https://www.cnblogs.com/zhouzhendong/p/7256007.htmlhttps://www.cnblogs.com/scau20110726/archive/2013/05/26/3100812.html模板:倍增:洛谷 P3379核心思想:二进制,预先处理出树上每个节点的往上走1、 2、 4、……2^n层的点,就可得...原创 2019-07-31 19:00:21 · 301 阅读 · 0 评论 -
洛谷P2633 Count on a tree 静态树链第k小(LCA+主席树)
https://www.luogu.org/problem/P2633展开题目描述给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文。输入格式第一行两个整数N,M。第二行有N个整数,其中第i个整数表示点i的权值。后面N-1行每行两个...原创 2019-08-04 20:06:20 · 200 阅读 · 0 评论 -
HDU 3078 Network LCA+查找第k大
http://acm.hdu.edu.cn/showproblem.php?pid=3078The ALPC company is now working on his own network system, which is connecting all N ALPC department. To economize on spending, the backbone network has ...原创 2019-08-03 12:28:25 · 197 阅读 · 0 评论