LCA
黑码
这个作者很懒,什么都没留下…
展开
-
codeforces E. Tree (lca 求最小公共祖先)
E. Tree Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree consisting of????nvertices numbered fr...原创 2020-03-27 10:48:24 · 422 阅读 · 0 评论 -
lca倍增 算法 最小公共祖先
转:http://www.cnblogs.com/yyf0309/p/5972701.html找最近公共父节点这问题很容易想到让两节点一起往上走最后相遇,但这样的dfs显然很慢,于是就需要倍增。就是用二进制的思维,以1,2,4,8等2的阶层步长接近答案,比一步一步向上要快很多。 所以要dfs出来点的2^k的父亲节点与该节点的深度。 找lca时先将下面的点升到与另一点同一深度,再用往上倍增找l原创 2017-06-01 14:29:39 · 864 阅读 · 0 评论 -
POJ 1330 LCA倍增模板题
A rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In the figure, each node is labeled with an integer from {1, 2,…,16}. Node 8 is the root of原创 2017-06-01 14:31:34 · 606 阅读 · 0 评论 -
poj 1470 LCA倍增 裸
Write a program that takes as input a rooted tree and a list of pairs of vertices. For each pair (u,v) the program determines the closest common ancestor of u and v in the tree. The closest common ance原创 2017-06-01 14:33:32 · 507 阅读 · 0 评论 -
qwb 与学姐 lca+mst
Problem H: qwb与学姐 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 96 Solved: 38 [Submit][Status][Web Board] Description qwb打算向学姐表白,可是学姐已经受够了他的骚扰,于是出了一个题想难住他: 已知一幅n个点m条边的无向图,定义路径的值为这条路径上最短的边的长度,原创 2017-06-03 13:31:06 · 624 阅读 · 0 评论 -
poj 3728 merchant 一个比较复杂的lca+dp
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 h原创 2017-06-03 13:48:30 · 413 阅读 · 0 评论 -
codeforeces 609E Minimum spanning tree for each edge MST +LCA
Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.For each edge (u, v) find the minimal possible weight of the spanning tree that原创 2017-06-15 01:16:43 · 417 阅读 · 0 评论 -
美团复赛 城市网络 (双倍增)
美团 CodeM 复赛」城市网络 内存限制:64 MiB时间限制:500 ms标准输入输出 题目描述有一个树状的城市网络(即 nnn 个城市由 n−1n-1n−1 条道路连接的连通图),首都为 111 号城市,每个城市售卖价值为 aia_iai 的珠宝。你是一个珠宝商,现在安排有 qqq 次行程,每次行程为从 uuu 号城市前往 vvv 号城市(走最短路径),保证 vvv 在 uuu 前往原创 2017-07-15 17:10:08 · 522 阅读 · 0 评论 -
hdu 6115 Factory(lca暴力)
我们将A省简化为由N个城市组成,某些城市之间存在双向道路,而且A省的交通有一个特点就是任意两个城市之间都能通过道路相互到达,且在不重复经过城市的情况下任意两个城市之间的到达方案都是唯一的。聪明的你一定已经发现,这些城市构成了树这样一个结构。 现在百度陆续开了许许多多的子公司。每家子公司又会在各城市中不断兴建属于该子公司的办公室。 由于各个子公司之间经常有资源的流动,所以公司员工常常想知道,两家子公司原创 2017-08-14 19:48:32 · 565 阅读 · 0 评论