mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>有一棵由 <code>n</code> 个节点组成的无向树,以 <code>0</code> 为根节点,节点编号从 <code>0</code> 到 <code>n - 1</code> 。给你一个长度为 <code>n - 1</code> 的二维 <strong>整数</strong> 数组 <code>edges</code> ,其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示在树上的节点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间存在一条边。另给你一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>coins</code> 和一个整数 <code>k</code> ,其中 <code>coins[i]</code> 表示节点 <code>i</code> 处的金币数量。</p>\n\n<p>从根节点开始,你必须收集所有金币。要想收集节点上的金币,必须先收集该节点的祖先节点上的金币。</p>\n\n<p>节点 <code>i</code> 上的金币可以用下述方法之一进行收集:</p>\n\n<ul>\n\t<li>收集所有金币,得到共计 <code>coins[i] - k</code> 点积分。如果 <code>coins[i] - k</code> 是负数,你将会失去 <code>abs(coins[i] - k)</code> 点积分。</li>\n\t<li>收集所有金币,得到共计 <code>floor(coins[i] / 2)</code> 点积分。如果采用这种方法,节点 <code>i</code> 子树中所有节点 <code>j</code> 的金币数 <code>coins[j]</code> 将会减少至 <code>floor(coins[j] / 2)</code> 。</li>\n</ul>\n\n<p>返回收集 <strong>所有</strong> 树节点的金币之后可以获得的最大积分。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png\" style=\"width: 60px; height: 316px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;\" />\n<pre>\n<strong>输入:</strong>edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\n<strong>输出:</strong>11 \n<strong>解释:</strong>\n使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。\n使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。\n使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ,总积分 = 10 + floor(3 / 2) = 11 。\n使用第二种方法收集节点 3 上的所有金币。总积分 = 11 + floor(1 / 2) = 11.\n可以证明收集所有节点上的金币能获得的最大积分是 11 。 \n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n<strong class=\"example\"> <img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/09/18/ex2.png\" style=\"width: 140px; height: 147px; padding: 10px; background: #fff; border-radius: .5rem;\" /></strong>\n\n<pre>\n<strong>输入:</strong>edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\n<strong>输出:</strong>16\n<strong>解释:</strong>\n使用第一种方法收集所有节点上的金币,因此,总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == coins.length</code></li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code><font face=\"monospace\">0 <= coins[i] <= 10<sup>4</sup></font></code></li>\n\t<li><code>edges.length == n - 1</code></li>\n\t<li><code><font face=\"monospace\">0 <= edges[i][0], edges[i][1] < n</font></code></li>\n\t<li><code><font face=\"monospace\">0 <= k <= 10<sup>4</sup></font></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 6,
|
||||
"likes": 9,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -167,7 +167,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.1K\", \"totalSubmission\": \"5.3K\", \"totalAcceptedRaw\": 2130, \"totalSubmissionRaw\": 5323, \"acRate\": \"40.0%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.6K\", \"totalSubmission\": \"6.3K\", \"totalAcceptedRaw\": 2620, \"totalSubmissionRaw\": 6282, \"acRate\": \"41.7%\"}",
|
||||
"hints": [
|
||||
"Let <code>dp[x][t]</code> be the maximum points we can get from the subtree rooted at node <code>x</code> and the second operation has been used <code>t</code> times in its ancestors.",
|
||||
"Note that the value of each <code>node <= 10<sup>4</sup></code>, so when <code>t >= 14</code> <code>dp[x][t]</code> is always <code>0</code>.",
|
||||
|
Reference in New Issue
Block a user