当前位置:网站首页>【学习笔记】最短路 +生成树
【学习笔记】最短路 +生成树
2022-06-28 08:06:00 【仰望星空的蚂蚁】
困难的题目
Opening Portals
好题!
我们称传送门为关键点。
设任意两个关键点之间距离为 dist(i,j) ,考虑到传送的性质,只需求出一个连接所有关键点的生成树,然后从任意一个关键点出发遍历,恰好为生成树的边权和。(有点绕)
如果我们以每个关键点为起点跑 dijkstra , 时间复杂度为 O ( n 2 log n ) O(n^2\log n) O(n2logn) 。
对于这个模型,我们有一个 多源最短路 算法 :
- 以每个关键点为起点,求出到每个点的最短距离
- 考虑枚举一条边 (u,v,w) ,将距这条边两个端点最近的两个关键点连起来:(相当于枚举中转点)

正确性是显然的。
特别地,MST 就是每个点都是关键点的情况 。
当然,一条边可能会在生成树上被计算多次。

Complete the MST
这题不需要高深算法。直接莽
可以直接跑完全图 MST ,然后找次小生成树 (分讨即可) 。
Jumping Around
boruvka 板题
Trial for Chief
好精巧的小构造!
万万没想到是最短路 !
考虑从 (i,j) 出发,相邻的颜色不同的格子距离为 1 ,颜色相同的格子距离为 0 ,找到距离最远的黑色格子,答案为 dist+1 。(特判全白)
考虑它的意义。相当于黑白交替,贪心地操作。
Flights
咕咕咕。。。
差分约束 + 最短路 !!

Capitalism
妙题 !
首先判断奇环一定无解。
这题的图很特殊,因为是双向边,所以从连通块的任意一点出发都能到达其他点 。因此我们枚举 S 作为起点,跑差分约束。

很巧的地方在于不会出现有边连的 dis[u]=dis[v] 的情况,否则会出现奇环。
这样可以得到一组合法的解。
然后要满足极差最大 。
不能建超级原点 。qwq
边栏推荐
- Flex layout
- Redis uses sentinel master-slave switching. What should the program do?
- sql主從複制搭建
- asp. Net error "/" server error in the application. String or binary data would be truncated. The statement...
- Soft exam -- software designer -- afternoon question data flow diagram DFD
- Section 5: zynq interrupt
- GPIO configuration of SOC
- LeetCode之三步问题
- Is it reliable to open a new bond registration account? Is it safe?
- Soft test -- software designer -- database design of afternoon questions
猜你喜欢

Online WPS tool

Static resource compression reduces bandwidth pressure and increases access speed

你了解TCP协议吗(一)?

Section VII starting principle and configuration of zynq

Activity implicit jump

Uvcgan: unt vision transformer cycle-consistent Gan for unpropared image-to-image translation

HJ prime factor

22/02/15 study notes

SOC timer and interrupt configuration

Kubernetes cluster command line tool kubectl
随机推荐
Resizing node of rediscluster cluster cluster mode
Online WPS tool
HJ进制转换
Estimation of SQL execution cost by MySQL query optimizer
MySQL single table access method
Ambari (VII) --- ambari integrated hue4.2 document (valid for personal test)
MySQL tablespace parsing
Redis persistence problem and final solution
How to insert a single quotation mark into a table as a data type in Oracle pl/sql
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
22/02/15 study notes
城联优品向英德捐赠抗洪救灾爱心物资
Is it reliable for flush to register and open an account? Is it safe?
flex布局
Three step problem of leetcode
Idea package together, using compact middle packages to solve &
Trigonometric transformation formula
Leetcode摆动序列系列
小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站
Is it reliable to open an account by digging money? Is it safe?