首页 > 其他 > 详细

[LeetCode] 924. Minimize Malware Spread 最大程度上减少恶意软件的传播

时间:2019-11-11 23:16:18      阅读:100      评论:0      收藏:0      [点我收藏+]



In a network of nodes, each node?i?is directly connected to another node?j?if and only if?graph[i][j] = 1.

Some nodes?initial?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?M(initial)?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?M(initial).? If multiple nodes could be removed to minimize?M(initial), return such a node with the smallest index.

Note that if a node was removed from the?initial?list of infected nodes, it may still be infected later as a result of the malware spread.

Example 1:

Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
Output: 0

Example 2:

Input: graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]
Output: 0

Example 3:

Input: graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]
Output: 1

Note:

  1. 1 < graph.length = graph[0].length <= 300
  2. 0 <= graph[i][j] == graph[j][i] <= 1
  3. graph[i][i] = 1
  4. 1 <= initial.length < graph.length
  5. 0 <= initial[i] < graph.length



Github 同步地址:

https://github.com/grandyang/leetcode/issues/924



类似题目:



参考资料:

https://leetcode.com/problems/minimize-malware-spread/



LeetCode All in One 题目讲解汇总(持续更新中...)

[LeetCode] 924. Minimize Malware Spread 最大程度上减少恶意软件的传播

原文:https://www.cnblogs.com/grandyang/p/11838844.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!