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> 位员工。公司准备了一张 <strong>圆形</strong> 的桌子,可以坐下 <strong>任意数目</strong> 的员工。</p>\n\n<p>员工编号为 <code>0</code> 到 <code>n - 1</code> 。每位员工都有一位 <strong>喜欢</strong> 的员工,每位员工 <strong>当且仅当</strong> 他被安排在喜欢员工的旁边,他才会参加会议。每位员工喜欢的员工 <strong>不会</strong> 是他自己。</p>\n\n<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>favorite</code> ,其中 <code>favorite[i]</code> 表示第 <code>i</code> 位员工喜欢的员工。请你返回参加会议的 <strong>最多员工数目</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/14/ex1.png\" style=\"width: 236px; height: 195px;\"></p>\n\n<pre><b>输入:</b>favorite = [2,2,1,2]\n<b>输出:</b>3\n<strong>解释:</strong>\n上图展示了公司邀请员工 0,1 和 2 参加会议以及他们在圆桌上的座位。\n没办法邀请所有员工参与会议,因为员工 2 没办法同时坐在 0,1 和 3 员工的旁边。\n注意,公司也可以邀请员工 1,2 和 3 参加会议。\n所以最多参加会议的员工数目为 3 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>favorite = [1,2,0]\n<b>输出:</b>3\n<b>解释:</b>\n每个员工都至少是另一个员工喜欢的员工。所以公司邀请他们所有人参加会议的前提是所有人都参加了会议。\n座位安排同图 1 所示:\n- 员工 0 坐在员工 2 和 1 之间。\n- 员工 1 坐在员工 0 和 2 之间。\n- 员工 2 坐在员工 1 和 0 之间。\n参与会议的最多员工数目为 3 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/14/ex2.png\" style=\"width: 219px; height: 220px;\"></p>\n\n<pre><b>输入:</b>favorite = [3,0,1,4,1]\n<b>输出:</b>4\n<b>解释:</b>\n上图展示了公司可以邀请员工 0,1,3 和 4 参加会议以及他们在圆桌上的座位。\n员工 2 无法参加,因为他喜欢的员工 0 旁边的座位已经被占领了。\n所以公司只能不邀请员工 2 。\n参加会议的最多员工数目为 4 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == favorite.length</code></li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= favorite[i] <= n - 1</code></li>\n\t<li><code>favorite[i] != i</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 52,
|
||||
"likes": 53,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"7.8K\", \"totalAcceptedRaw\": 2318, \"totalSubmissionRaw\": 7791, \"acRate\": \"29.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.4K\", \"totalSubmission\": \"7.9K\", \"totalAcceptedRaw\": 2357, \"totalSubmissionRaw\": 7911, \"acRate\": \"29.8%\"}",
|
||||
"hints": [
|
||||
"From the given array favorite, create a graph where for every index i, there is a directed edge from favorite[i] to i. The graph will be a combination of cycles and chains of acyclic edges. Now, what are the ways in which we can choose employees to sit at the table?",
|
||||
"The first way by which we can choose employees is by selecting a cycle of the graph. It can be proven that in this case, the employees that do not lie in the cycle can never be seated at the table.",
|
||||
|
Reference in New Issue
Block a user