当前位置:网站首页>【学习笔记】树的直径,重心
【学习笔记】树的直径,重心
2022-07-23 21:46:00 【仰望星空的蚂蚁】
草莓 Strawberry
膜拜 EternalAlexander- 假设 ∣ S ∣ ≥ 2 |S|\ge 2 ∣S∣≥2,设直径的两个端点为 s s s和 t t t
- 显然我们知道直径有一个中心
- 假如我起点不在半径上,那么我下一步会把所有在半径上的点占领
- 但是显然我可以把起点调整到半径上,然后把所有半径上的点占领
- 然后我们对于其他的点求出到半径上的点的最大距离,排序过后就可以得到 S × G S\times G S×G的的最大值
CF1387B2
- 对于一条边 ( u , v ) (u,v) (u,v),每条边对答案贡献最多为 2 min ( s i z [ u ] , n − s i z [ u ] ) 2\min(siz[u],n-siz[u]) 2min(siz[u],n−siz[u])
- 考虑找到重心,对除了重心外的点两两跨子树匹配
- 因为任意子树大小不超过 n 2 \frac{n}{2} 2n,所以存在两两配对的方案
- 细节问题就不说了
树的直径
- 给定一棵树,求编号 [ l , r ] [l,r] [l,r]内两点距离的最大值。 n ≤ 1 0 5 n\le 10^5 n≤105
- 考虑树上两个点集 S S S和 T T T,若集合 S S S中的最远点对是 u → v u\to v u→v, T T T中的最远点对是 w → x w\to x w→x,那么 S ∪ T S∪T S∪T的最远点对一定是 u → v u\to v u→v, w → x w\to x w→x, u → w u\to w u→w, u → x u\to x u→x, v → w v\to w v→w, v → x v\to x v→x 六对之一
- 可以线段树维护。可以用欧拉序列求 L C A LCA LCA平衡复杂度做到预处理 O ( n log n ) O(n\log n) O(nlogn),询问 O ( 1 ) O(1) O(1)。
- 总复杂度 O ( n log n ) O(n\log n) O(nlogn)。
哈夫曼树(Hufman Tree)
- 构造方法:每次取权值最小的两个点,加一个新的节点作为他们的父节点,将新的节点权值设为它们的前缀和。
边栏推荐
- VLAN comprehensive experiment
- Unity - 3D mathematics -vector3
- Payment products and their usage scenarios
- Chapter1 data cleaning
- U++学习笔记 基础人物轴绑定及映射绑定
- Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
- Complete set of official openlayers instances
- Why cluster chat server introduces load balancer
- Distributed transaction scheme: best effort notification scheme
- jedis 6---redisson和jedis的入门和不同
猜你喜欢

Cmake learning

集群聊天服务器:数据库表的设计

寻找消失的类名

Why cluster chat server introduces load balancer

VLAN comprehensive experiment

A stack of digital robots were selected in Gartner's China AI market guide
![[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication](/img/29/b73edbdb2409f40c904d126f9185d1.png)
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication

Jedis 6 - Introduction and difference between redisson and jedis

Apprentissage Lambda (utilisation du comparateur après tri, regroupement après collecte avec collectors.groupingby)

大学数据库创建与查询实战——数据库表设计
随机推荐
ESP32 的 I2C 原理 & 应用入门
Chapter1 data cleaning
Redis common commands correspond to redisson object operations
Deep learning - NLP classic papers, courses, papers and other resources sorting and sharing
博客总排名为918
集群聊天服务器为什么引入负载均衡器
Synchronized同步锁的基本原理
寻找消失的类名
给定一个以数字组成的数组,实现输出id为数字,并且从小到大排序的name
U++ 学习笔记 控制物体Scale
DBSCAN点云聚类
CMake的学习
A stack of digital robots were selected in Gartner's China AI market guide
SQL injection attack
138 - query case - knowledge points involved: foreach traversal & computed calculation attributes & V-for loop
Jedis 6 - Introduction and difference between redisson and jedis
The total ranking of blogs is 918
Jianzhi offer II 115. reconstruction sequence: topological sorting construction problem
U++ 事件
集群聊天服务器:集群与分布式理论