All problems
Network Resilience Remove-Node Check
Problem
Measure the resilience impact of removing each node by counting the resulting connected components.
For every node, remove it, count components among the remaining nodes, and collect the counts in node order. Removing a node from an edgeless graph leaves isolated components. edges is a list of [u, v] pairs.
Hint
Nodes whose removal fragments the network are the critical infrastructure.
Test cases
case 1
in: [4,[[0,1],[1,2],[2,3]]]
expected: [1,2,2,1]
case 2
in: [4,[[0,1],[0,2],[0,3]]]
expected: [3,1,1,1]
case 3
in: [3,[[0,1],[1,2],[2,0]]]
expected: [1,1,1]
case 4
in: [3,[]]
expected: [2,2,2]
Starter codePython
def node_removal_impact(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor