当前位置:网站首页>F-牛妹的苹果树(直径合并)
F-牛妹的苹果树(直径合并)
2022-04-23 06:21:00 【Zimba_】
题意:
一棵 n n n个结点的树,每条边有个边权 w i wi wi。有 q q q次询问,每次询问 l l l和 r r r,求 m a x ( d i s t ( u , v ) ) , l ≤ u ≤ v ≤ r max(dist(u,v)),l\leq u\leq v\leq r max(dist(u,v)),l≤u≤v≤r。
( 1 ≤ n , q ≤ 300000 ) (1\leq n,q\leq 300000) (1≤n,q≤300000)
做法:
这里有一个结论:已知两个子图的直径端点,那么两个图合并后的直径,就在这四个点中取最远的两个点。
所以这题考虑倍增处理出ST表。需要两个区间的最值合并,只要保存每个区间的直径端点,就可以合并得到新的直径了。
代码:
题解这么简单,代码YY一下就好了。
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43785386/article/details/108027552
边栏推荐
猜你喜欢

SDC intelligent communication patrol management system of Nanfang investment building

el-table 横向滚动条固定在可视窗口底部

使用compressorjs压缩图片,优化功能,压缩所有格式的图片

Machine vision series (02) -- tensorflow2 3 + win10 + GPU installation

利用mysql-binlog恢复数据

Beifeng communication helps Zhanjiang fire brigade build PDT wireless communication system

USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference

Solution of self Networking Wireless Communication intercom system in Beifeng oil and gas field

Educational Codeforces Round 81 (Rated for Div. 2)

van-uploader上传图片实现过程、使用原生input实现上传图片
随机推荐
PyTorch 12. Hook usage
Educational Codeforces Round 81 (Rated for Div. 2)
Pycharm
保洁阿姨都能看懂的中国剩余定理和扩展中国剩余定理
可视化之路(十一)matplotlib颜色详解
kaggle-房价预测实战
可视化常见绘图(三)面积图
通用型冒泡、选择、插入、希尔、快速排序的代码实现
xdotool按键精灵
Javscript gets the real suffix of the file
华为云MVP邮件
数据分析学习(一)数据分析和Numpy基础
Dirichlet 前缀和(数论优化式子复杂度利器)
[hdu6868]Absolute Math(推式子+莫比乌斯反演)
Tensorflow安装后ImportError: DLL load failed: 找不到指定的模块,且国内安装缓慢
[2020WC Day2]F.采蘑菇的克拉莉丝(子树和查询、轻重儿子思想)
社区版阿里MQ普通消息发送订阅Demo
Emergency communication system for flood control and disaster relief
van-uploader上传图片实现过程、使用原生input实现上传图片
colab