Imagine a computer network under cyber attack! You have a network of n nodes represented as an n x n adjacency matrix graph, where nodes are connected if graph[i][j] == 1.
The Attack Scenario: Some nodes in the initial array are already infected with malware. The malware spreads through direct connections - whenever two nodes are connected and at least one is infected, both become infected. This continues until no more nodes can be infected.
Your Mission: You can completely remove exactly one infected node (and all its connections) from the network before the malware spreads. Your goal is to minimize the final number of infected nodes M(initial).
Return: The index of the node to remove that minimizes the spread. If multiple nodes give the same minimum result, return the smallest index.
Input & Output
Constraints
- n == graph.length == graph[i].length
- 2 โค n โค 300
- graph[i][j] is 0 or 1
- graph[i][i] == 1
- 1 โค initial.length < n
- 0 โค initial[i] < n
- All values in initial are unique