In a network of nodes, each node is directly connected to another node if and only if .
Some nodes are initially infected by malware. Whenever two nodes are directly connected and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.
Suppose is the final number of nodes infected with malware in the entire network, after the spread of malware stops.
We will remove one node from the initial list. Return the node that if removed, would minimize . If multiple nodes could be removed to minimize , return such a node with the smallest index.
Note that if a node was removed from the list of infected nodes, it may still be infected later as a result of the malware spread.
Example 1:
Example 2:
Example 3:
Note:
在节点 络中,只有当 时,每个节点 能够直接连接到另一个节点 。
一些节点 最初被恶意软件感染。只要两个节点直接连接,且其中至少一个节点受到恶意软件的感染,那么两个节点都将被恶意软件感染。这种恶意软件的传播将继续,直到没有更多的节点可以被这种方式感染。
假设 是在恶意软件停止传播之后,整个 络中感染恶意软件的最终节点数。
我们可以从初始列表中删除一个节点。如果移除这一节点将最小化 , 则返回该节点。如果有多个节点满足条件,就返回索引最小的节点。
请注意,如果某个节点已从受感染节点的列表 中删除,它以后可能仍然因恶意软件传播而受到感染。
示例 1:
示例 2:
示例 3:
提示:
2592ms
2708ms
3424ms
相关资源:精通Matlab数字图像处理与识别电子书,张铮 倪红霞 苑春苗 杨立红…
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!