Imagine you're a cybersecurity expert dealing with a malware outbreak in a computer network! You have a network of n computers represented as an n ร n adjacency matrix graph, where graph[i][j] == 1 means computers i and j are directly connected.
Some computers in the initial array are already infected with malware. The malware spreads according to this rule: whenever two computers are directly connected and at least one is infected, both become infected. This continues until no more computers can be infected.
Here's your mission: You can quarantine exactly one computer from the initial infected list before the malware starts spreading. Your goal is to find which computer to quarantine to minimize the total number of infected computers after the spread stops.
If multiple computers would result in the same minimum infection count, return the one with the smallest index. Note that a quarantined computer might still get infected later if the malware reaches it through other paths!
Input & Output
Constraints
- n == graph.length == graph[i].length
- 2 โค n โค 300
- graph[i][j] is 0 or 1
- graph[i][i] == 1
- graph[i][j] == graph[j][i]
- 1 โค initial.length โค n
- All integers in initial are unique