当前位置:网站首页>[learning notes] diameter and center of gravity of the tree
[learning notes] diameter and center of gravity of the tree
2022-07-23 21:48:00 【Ants looking up at the starry sky】
strawberry Strawberry
Worship EternalAlexander- hypothesis ∣ S ∣ ≥ 2 |S|\ge 2 ∣S∣≥2, Let the two ends of the diameter be s s s and t t t
- Obviously we know that the diameter has a center
- If my starting point is not on the radius , Then I will occupy all the points in the radius next
- But obviously I can adjust the starting point to the radius , Then take all the points on the radius
- Then we find the maximum distance to the point on the radius for other points , After sorting, you can get S × G S\times G S×G The maximum value of
CF1387B2
- For an edge ( u , v ) (u,v) (u,v), Each side contributes up to 2 min ( s i z [ u ] , n − s i z [ u ] ) 2\min(siz[u],n-siz[u]) 2min(siz[u],n−siz[u])
- Consider finding the center of gravity , Match the two span subtrees of points other than the center of gravity
- Because the size of any subtree does not exceed n 2 \frac{n}{2} 2n, So there is a pairing scheme
- Let's not talk about the details
The diameter of the tree
- Given a tree , Seek number [ l , r ] [l,r] [l,r] The maximum distance between two points in . n ≤ 1 0 5 n\le 10^5 n≤105
- Consider two point sets on the tree S S S and T T T, If we gather S S S The farthest point in the pair is u → v u\to v u→v, T T T The farthest point in the pair is w → x w\to x w→x, that S ∪ T S∪T S∪T The farthest point of must be 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 One of six pairs
- You can maintain the line segment tree . We can use Euler sequence to find L C A LCA LCA Balance the complexity to achieve preprocessing O ( n log n ) O(n\log n) O(nlogn), inquiry O ( 1 ) O(1) O(1).
- The sum O ( n log n ) O(n\log n) O(nlogn).
Huffman tree (Hufman Tree)
- Construction method : Take the two points with the smallest weight each time , Add a new node as their parent node , Set the new node weights to their prefixes and .
边栏推荐
猜你喜欢

【愚公系列】2022年06月 .NET架构班 084-微服务专题 Abp vNext微服务通信

HANA SQL 的Union和Union All

PCL出错:error C2589“(“:“::“右边的非法标记)

大淘营批量采集商品,如何将未上传的宝贝保存下来等后面再导入采集上传

lambda學習(sort後面的Comparator的使用,collection後使用Collectors.groupingBy分組)

A stack of digital robots were selected in Gartner's China AI market guide

Customer exit variable in query

Golang invalid argument to intn报错的解决

Machine learning exercises -- right rate regression

U++ learning notes tsubclassof()
随机推荐
Cesium keyboard and mouse control camera roaming (source code + principle explanation)
集群聊天服务器:网络模块ChatServer
Cookie 和 Session
寻找消失的类名
05_ UE4 advanced_ Material UV scaling
SQL injection attack
分布式能源的不确定性——风速测试(Matlab代码实现)
欧氏聚类(API)及其单木分割
节流和防抖的说明和实现
Jedis 6 - Introduction and difference between redisson and jedis
Compare kernelshap and treeshap based on speed, complexity and other factors
Serveur de chat de Cluster: conception de la table de base de données
Yushu A1 robot dog gesture control
基于速度、复杂性等因素比较KernelSHAP和TreeSHAP
Day109.尚医通:集成Nacos、医院列表、下拉列表查询、医院上线功能、医院详情查询
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication
淘宝助理停用,用大淘营导入数据包上传宝贝提示“主图为必填项,不能为空”是什么原因?如何解决?
集群聊天服务器:数据库表的设计
Cluster chat server: creation of project directory
Quick review of interview (III): probability theory and mathematical statistics