From 1de1a3e4f313f226747e73afc76d76954b19b061 Mon Sep 17 00:00:00 2001 From: Michael Lee <41327586+chl131@users.noreply.github.com> Date: Sun, 8 Jun 2025 17:52:55 -0700 Subject: [PATCH 1/2] upper bound of TotalNumbersBeginWith() should be (prefix * exp + exp - 1) in problem 440.K-th-Smallest-in-Lexicographical-Order.cpp --- .../440.K-th-Smallest-in-Lexicographical-Order.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/440.K-th-Smallest-in-Lexicographical-Order/440.K-th-Smallest-in-Lexicographical-Order.cpp b/Others/440.K-th-Smallest-in-Lexicographical-Order/440.K-th-Smallest-in-Lexicographical-Order.cpp index fe5afc34a..a6a2f39ac 100644 --- a/Others/440.K-th-Smallest-in-Lexicographical-Order/440.K-th-Smallest-in-Lexicographical-Order.cpp +++ b/Others/440.K-th-Smallest-in-Lexicographical-Order/440.K-th-Smallest-in-Lexicographical-Order.cpp @@ -33,7 +33,7 @@ class Solution { while (1) { long lower = prefix * exp; - long upper = prefix * exp + exp + 1; + long upper = prefix * exp + exp - 1; if (lower > n) break; if (lower <= n && upper >= n) { From fd58a351e18285424d718de3280a1d314683fcfd Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Fri, 13 Jun 2025 20:07:11 -0700 Subject: [PATCH 2/2] Update Readme.md --- .../Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Binary_Search/3553.Minimum-Weighted-Subgraph-With-the-Required-Paths-II/Readme.md b/Binary_Search/3553.Minimum-Weighted-Subgraph-With-the-Required-Paths-II/Readme.md index 21b7d3d06..f210532f1 100644 --- a/Binary_Search/3553.Minimum-Weighted-Subgraph-With-the-Required-Paths-II/Readme.md +++ b/Binary_Search/3553.Minimum-Weighted-Subgraph-With-the-Required-Paths-II/Readme.md @@ -1,3 +1,9 @@ ### 3553.Minimum-Weighted-Subgraph-With-the-Required-Paths-II 本题的第一个知识点是:在一棵树里,联通u,v,w三个节点的最小子树的权重和,就是`[dist(u,v)+dist(u,w)+dist(v,w)]/2`. + +本体的第二个知识点是:在一棵树里,联通x,y两点的路径长度,等于`dist(r,x)+dist(r,y)-2*dist(r,c)`,其中r是整棵树的根节点,c是x和y的LCA(lowest common ancester)。 + +任意一点到距离根节点的距离dist(r,x)可以通过DFS得到。于是本题的关键点就是求任意两点的LCA,于是就是一个binary list经典题。 + +我们需要处理得到一个数组up[v][k],表示节点v往上(朝根节点方向)走2^k步能够得到的位置。转移方程就是`up[v][k] = up[up[v][k-1]][k-1]`. 边界条件就是对于一对父子节点a->b,有`up[b][0]=a`.