mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个整数 <code>n</code> ,表示有 <code>n</code> 节课,课程编号从 <code>1</code> 到 <code>n</code> 。同时给你一个二维整数数组 <code>relations</code> ,其中 <code>relations[j] = [prevCourse<sub>j</sub>, nextCourse<sub>j</sub>]</code> ,表示课程 <code>prevCourse<sub>j</sub></code> 必须在课程 <code>nextCourse<sub>j</sub></code> <strong>之前</strong> 完成(先修课的关系)。同时给你一个下标从 <strong>0</strong> 开始的整数数组 <code>time</code> ,其中 <code>time[i]</code> 表示完成第 <code>(i+1)</code> 门课程需要花费的 <strong>月份</strong> 数。</p>\n\n<p>请你根据以下规则算出完成所有课程所需要的 <strong>最少</strong> 月份数:</p>\n\n<ul>\n\t<li>如果一门课的所有先修课都已经完成,你可以在 <strong>任意</strong> 时间开始这门课程。</li>\n\t<li>你可以 <strong>同时</strong> 上 <strong>任意门课程</strong> 。</li>\n</ul>\n\n<p>请你返回完成所有课程所需要的 <strong>最少</strong> 月份数。</p>\n\n<p><strong>注意:</strong>测试数据保证一定可以完成所有课程(也就是先修课的关系构成一个有向无环图)。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/07/ex1.png\" style=\"width: 392px; height: 232px;\"></strong></p>\n\n<pre><strong>输入:</strong>n = 3, relations = [[1,3],[2,3]], time = [3,2,5]\n<b>输出:</b>8\n<b>解释:</b>上图展示了输入数据所表示的先修关系图,以及完成每门课程需要花费的时间。\n你可以在月份 0 同时开始课程 1 和 2 。\n课程 1 花费 3 个月,课程 2 花费 2 个月。\n所以,最早开始课程 3 的时间是月份 3 ,完成所有课程所需时间为 3 + 5 = 8 个月。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/10/07/ex2.png\" style=\"width: 500px; height: 365px;\"></strong></p>\n\n<pre><b>输入:</b>n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]\n<b>输出:</b>12\n<b>解释:</b>上图展示了输入数据所表示的先修关系图,以及完成每门课程需要花费的时间。\n你可以在月份 0 同时开始课程 1 ,2 和 3 。\n在月份 1,2 和 3 分别完成这三门课程。\n课程 4 需在课程 3 之后开始,也就是 3 个月后。课程 4 在 3 + 4 = 7 月完成。\n课程 5 需在课程 1,2,3 和 4 之后开始,也就是在 max(1,2,3,7) = 7 月开始。\n所以完成所有课程所需的最少时间为 7 + 5 = 12 个月。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>\n\t<li><code>0 <= relations.length <= min(n * (n - 1) / 2, 5 * 10<sup>4</sup>)</code></li>\n\t<li><code>relations[j].length == 2</code></li>\n\t<li><code>1 <= prevCourse<sub>j</sub>, nextCourse<sub>j</sub> <= n</code></li>\n\t<li><code>prevCourse<sub>j</sub> != nextCourse<sub>j</sub></code></li>\n\t<li>所有的先修课程对 <code>[prevCourse<sub>j</sub>, nextCourse<sub>j</sub>]</code> 都是 <strong>互不相同</strong> 的。</li>\n\t<li><code>time.length == n</code></li>\n\t<li><code>1 <= time[i] <= 10<sup>4</sup></code></li>\n\t<li>先修课程图是一个有向无环图。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 18,
|
||||
"likes": 19,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.5K\", \"totalSubmission\": \"4.5K\", \"totalAcceptedRaw\": 2535, \"totalSubmissionRaw\": 4466, \"acRate\": \"56.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.7K\", \"totalSubmission\": \"4.6K\", \"totalAcceptedRaw\": 2651, \"totalSubmissionRaw\": 4636, \"acRate\": \"57.2%\"}",
|
||||
"hints": [
|
||||
"What is the earliest time a course can be taken?",
|
||||
"How would you solve the problem if all courses take equal time?",
|
||||
|
Reference in New Issue
Block a user