|
| 1 | +--- |
| 2 | +comments: true |
| 3 | +difficulty: 中等 |
| 4 | +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3493.Properties%20Graph/README.md |
| 5 | +--- |
| 6 | + |
| 7 | +<!-- problem:start --> |
| 8 | + |
| 9 | +# [3493. 属性图](https://leetcode.cn/problems/properties-graph) |
| 10 | + |
| 11 | +[English Version](/solution/3400-3499/3493.Properties%20Graph/README_EN.md) |
| 12 | + |
| 13 | +## 题目描述 |
| 14 | + |
| 15 | +<!-- description:start --> |
| 16 | + |
| 17 | +<p>给你一个二维整数数组 <code>properties</code>,其维度为 <code>n x m</code>,以及一个整数 <code>k</code>。</p> |
| 18 | + |
| 19 | +<p>定义一个函数 <code>intersect(a, b)</code>,它返回数组 <code>a</code> 和 <code>b</code> 中<strong> 共有的不同整数的数量 </strong>。</p> |
| 20 | + |
| 21 | +<p>构造一个 <strong>无向图</strong>,其中每个索引 <code>i</code> 对应 <code>properties[i]</code>。如果且仅当 <code>intersect(properties[i], properties[j]) >= k</code>(其中 <code>i</code> 和 <code>j</code> 的范围为 <code>[0, n - 1]</code> 且 <code>i != j</code>),节点 <code>i</code> 和节点 <code>j</code> 之间有一条边。</p> |
| 22 | + |
| 23 | +<p>返回结果图中<strong> 连通分量 </strong>的数量。</p> |
| 24 | + |
| 25 | +<p> </p> |
| 26 | + |
| 27 | +<p><strong class="example">示例 1:</strong></p> |
| 28 | + |
| 29 | +<div class="example-block"> |
| 30 | +<p><strong>输入:</strong> <span class="example-io">properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1</span></p> |
| 31 | + |
| 32 | +<p><strong>输出:</strong> <span class="example-io">3</span></p> |
| 33 | + |
| 34 | +<p><strong>解释:</strong></p> |
| 35 | + |
| 36 | +<p>生成的图有 3 个连通分量:</p> |
| 37 | + |
| 38 | +<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665594-CDVPWz-image.png" style="width: 279px; height: 171px;" /></p> |
| 39 | +</div> |
| 40 | + |
| 41 | +<p><strong class="example">示例 2:</strong></p> |
| 42 | + |
| 43 | +<div class="example-block"> |
| 44 | +<p><strong>输入:</strong> <span class="example-io">properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2</span></p> |
| 45 | + |
| 46 | +<p><strong>输出:</strong> <span class="example-io">1</span></p> |
| 47 | + |
| 48 | +<p><strong>解释:</strong></p> |
| 49 | + |
| 50 | +<p>生成的图有 1 个连通分量:</p> |
| 51 | + |
| 52 | +<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665565-NzYlYH-screenshot-from-2025-02-27-23-58-34.png" style="width: 219px; height: 171px;" /></p> |
| 53 | +</div> |
| 54 | + |
| 55 | +<p><strong class="example">示例 3:</strong></p> |
| 56 | + |
| 57 | +<div class="example-block"> |
| 58 | +<p><strong>输入:</strong> <span class="example-io">properties = [[1,1],[1,1]], k = 2</span></p> |
| 59 | + |
| 60 | +<p><strong>输出:</strong> <span class="example-io">2</span></p> |
| 61 | + |
| 62 | +<p><strong>解释:</strong></p> |
| 63 | + |
| 64 | +<p><code>intersect(properties[0], properties[1]) = 1</code>,小于 <code>k</code>。因此在图中 <code>properties[0]</code> 和 <code>properties[1]</code> 之间没有边。</p> |
| 65 | +</div> |
| 66 | + |
| 67 | +<p> </p> |
| 68 | + |
| 69 | +<p><strong>提示:</strong></p> |
| 70 | + |
| 71 | +<ul> |
| 72 | + <li><code>1 <= n == properties.length <= 100</code></li> |
| 73 | + <li><code>1 <= m == properties[i].length <= 100</code></li> |
| 74 | + <li><code>1 <= properties[i][j] <= 100</code></li> |
| 75 | + <li><code>1 <= k <= m</code></li> |
| 76 | +</ul> |
| 77 | + |
| 78 | +<!-- description:end --> |
| 79 | + |
| 80 | +## 解法 |
| 81 | + |
| 82 | +<!-- solution:start --> |
| 83 | + |
| 84 | +### 方法一 |
| 85 | + |
| 86 | +<!-- tabs:start --> |
| 87 | + |
| 88 | +#### Python3 |
| 89 | + |
| 90 | +```python |
| 91 | + |
| 92 | +``` |
| 93 | + |
| 94 | +#### Java |
| 95 | + |
| 96 | +```java |
| 97 | + |
| 98 | +``` |
| 99 | + |
| 100 | +#### C++ |
| 101 | + |
| 102 | +```cpp |
| 103 | + |
| 104 | +``` |
| 105 | + |
| 106 | +#### Go |
| 107 | + |
| 108 | +```go |
| 109 | + |
| 110 | +``` |
| 111 | + |
| 112 | +<!-- tabs:end --> |
| 113 | + |
| 114 | +<!-- solution:end --> |
| 115 | + |
| 116 | +<!-- problem:end --> |
0 commit comments