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)/尽量减少恶意软件的传播 [minimize-malware-spread].html
2022-03-29 12:43:11 +08:00

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 × n</code> 个邻接矩阵图<meta charset="UTF-8" />&nbsp;<code>graph</code>&nbsp;表示。在节点网络中,当 <code>graph[i][j] = 1</code>&nbsp;时,表示节点&nbsp;<code>i</code>&nbsp;能够直接连接到另一个节点 <code>j</code>&nbsp;</p>
<p>一些节点&nbsp;<code>initial</code>&nbsp;最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。</p>
<p>假设 <code>M(initial)</code> 是在恶意软件停止传播之后,整个网络中感染恶意软件的最终节点数。</p>
<p>如果从&nbsp;<code>initial</code>&nbsp;<strong>移除某一节点</strong>能够最小化 <code>M(initial)</code> 返回该节点。如果有多个节点满足条件,就返回<strong>索引最小</strong>的节点。</p>
<p>请注意,如果某个节点已从受感染节点的列表 <code>initial</code> 中删除,它以后仍有可能因恶意软件传播而受到感染。</p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 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>示例 2</strong></p>
<pre>
<strong>输入:</strong>graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]
<strong>输出:</strong>0
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]
<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]&nbsp;==&nbsp;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;= n</code></li>
<li><code>0 &lt;= initial[i] &lt;= n - 1</code></li>
<li><code>initial</code>&nbsp;中所有整数均<strong>不重复</strong></li>
</ul>