HardRating 1869
924. Minimize Malware Spread
arrayhash-tabledepth-first-searchbreadth-first-searchunion-findgraph
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Build Union-Find from adjacency matrix
2. For each initial infected node, map its component root to the list of infected nodes in that component
3. Sort initial array
4. For each initial node:
a. If its component has exactly 1 infected node:
- Compare component size with best; update if larger (or smaller index on tie)
5. If no single-source component found, return smallest index in initial
6. Return the best node to remove