1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/尽量减少恶意软件的传播 II [minimize-malware-spread-ii].html

53 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个由 <code>n</code> 个节点组成的网络,用 <code>n x n</code> 个邻接矩阵&nbsp;<code>graph</code>&nbsp;表示。在节点网络中,只有当&nbsp;<code>graph[i][j] = 1</code>&nbsp;时,节点&nbsp;<code>i</code>&nbsp;能够直接连接到另一个节点&nbsp;<code>j</code></p>
<p>一些节点&nbsp;<code>initial</code>&nbsp;最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。</p>
<p>假设&nbsp;<code>M(initial)</code>&nbsp;是在恶意软件停止传播之后,整个网络中感染恶意软件的最终节点数。</p>
<p>我们可以从 <code>initial</code>&nbsp;<strong>删除一个节点</strong><strong>并完全移除该节点以及从该节点到任何其他节点的任何连接。</strong></p>
<p>请返回移除后能够使&nbsp;<code>M(initial)</code>&nbsp;最小化的节点。如果有多个节点满足条件,返回索引 <strong>最小的节点</strong></p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
<strong>输出:</strong>0
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]
<strong>输出:</strong>1
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<meta charset="UTF-8" />
<ul>
<li><code>n == graph.length</code></li>
<li><code>n == graph[i].length</code></li>
<li><code>2 &lt;= n &lt;= 300</code></li>
<li><code>graph[i][j]</code>&nbsp;&nbsp;<code>0</code>&nbsp;&nbsp;<code>1</code>.</li>
<li><code>graph[i][j] == graph[j][i]</code></li>
<li><code>graph[i][i] == 1</code></li>
<li><code>1 &lt;= initial.length &lt;&nbsp;n</code></li>
<li><code>0 &lt;= initial[i] &lt;= n - 1</code></li>
<li>&nbsp;<code>initial</code>&nbsp;中每个整数都<strong>不同</strong></li>
</ul>