928. Minimize Malware Spread II Hard
1/**
2 * [928] Minimize Malware Spread II
3 *
4 * You are given a network of n nodes represented as an n x n adjacency matrix graph, where the i^th node is directly connected to the j^th node if graph[i][j] == 1.
5 * 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.
6 * Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.
7 * We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.
8 * 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.
9 *
10 * Example 1:
11 * Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
12 * Output: 0
13 * Example 2:
14 * Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]
15 * Output: 1
16 * Example 3:
17 * Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]
18 * Output: 1
19 *
20 * Constraints:
21 *
22 * n == graph.length
23 * n == graph[i].length
24 * 2 <= n <= 300
25 * graph[i][j] is 0 or 1.
26 * graph[i][j] == graph[j][i]
27 * graph[i][i] == 1
28 * 1 <= initial.length < n
29 * 0 <= initial[i] <= n - 1
30 * All the integers in initial are unique.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimize-malware-spread-ii/
36// discuss: https://leetcode.com/problems/minimize-malware-spread-ii/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn min_malware_spread(graph: Vec<Vec<i32>>, initial: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_928() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.