![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
lca
文章平均质量分 71
tomjobs
别慌,慌也没用
展开
-
Codeforces-1486 F. Pairs of Paths(计数,dfs序树状数组,LCA)
题意: 一棵树,给你mmm条路径,问有多少对路径满足只有一个交点。 思路: 设1为根,然后找出每个路径两个端点的lcalcalca。可以得到路径间仅一个交点只有两种情况:两个路径lcalcalca相同,一个路径的lcalcalca在另外一个路径上。 先对每个路径进行一下处理,除了记录两个端点x,yx,yx,y记录其lcalcalca,还要保存两个端点对应在lcalcalca子树中位置a,ba,ba,b。并且要保证a<ba<ba<b(交换实现)。对于xxx或者yyy本身就是lcalcal.原创 2021-02-20 16:22:30 · 269 阅读 · 0 评论 -
I - Imperial roads Gym - 101889I(LCA+最小生成树)
题意: 一个有权图,求每次必须选一个边的最小生成树值。 思路: 先跑出最小生成树,然后对于给出的x,y,在最小生成树上找到其路径,删掉一条最大边,再加上(x,y)这条边就是最小生成树的值了。 #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<map> using namespace std; typedef long long ll; c原创 2020-10-28 11:18:42 · 208 阅读 · 0 评论 -
PreSuffix ZOJ - 3995(AC自动机 fail树上跑LCA)
We define a string of length ll as an array S[1…l]S[1…l]. All the elements within it belongs to a finite set \sum={a,b,…,z}∑={a,b,…,z}. Let \text{Prefix}(S,i)=S[1…i]Prefix(S,i)=S[1…i] be one prefix of SS with a length of ii. Similarly, \text{Suffix}(S,j)=S原创 2020-10-13 23:30:05 · 209 阅读 · 0 评论 -
I - Tourists Gym - 101002I(LCA)
题意: 一棵树,求所有路径i−>ji -> ji−>j,满足j>ij>ij>i,且jjj是iii倍数的距离和。 思路: 没什么好说的,直接跑LCA统计就行了。 #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; typedef long.原创 2020-05-25 10:07:09 · 257 阅读 · 0 评论 -
AcWing 352. 闇の連鎖(树上差分,lca)
传说中的暗之连锁被人们称为 Dark。 Dark 是人类内心的黑暗的产物,古今中外的勇者们都试图打倒它。 经过研究,你发现 Dark 呈现无向图的结构,图中有 N 个节点和两类边,一类边被称为主要边,而另一类被称为附加边。 Dark 有 N – 1 条主要边,并且 Dark 的任意两个节点之间都存在一条只由主要边构成的路径。 另外,Dark 还有 M 条附加边。 你的任务是把 Dark 斩为不连通...原创 2020-03-31 00:10:47 · 221 阅读 · 0 评论 -
lca倍增和离线tarjan模板
https://www.luogu.org/problem/P3379 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e6 + 7; int head[maxn],to[maxn],nex[maxn],d[max...原创 2019-09-14 11:55:38 · 203 阅读 · 0 评论 -
The merchant POJ - 3728(倍增dp + 在线lca)
There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When ...原创 2019-11-18 21:08:39 · 264 阅读 · 0 评论