In the neighbourhood of Iceland, there are a total of n houses. House i and House j are connected to each other if there exists a road from house i to house j. In this neighbourhood, if a robber breaks into a house i, he/she can also break into any house j that has a road from House i (i.e. house i and house j are connected through a road). A robber will continue breaking into houses until he/she can no more break into the remaining houses in the manner specified.
There are some initial number of houses that have been broken by a robber and let M denote the final number of houses that will be broke by the robber. In this neighbourhood, there is a man by the name John who has the special ability to remove exactly one house from the initial set of broken houses. Help John to identify the house, which when removed from the list of initial broken houses, would minimize the value M.
It is to be noted that the house that was removed from the initial set of broken houses might still get broken by the robbers at a later point of time due to breaking of the houses connected by a road to it.
The road connectivity of the houses can be considered as an n*n adjaceny matrix graph called road, where the ith house is directly connected to the jth house if road[i][j]==1.
Input: Adjaceny matrix graph denoting road connectivity, and set of initial broken houses
Output: The index of house(0-indexed) which when removed from initial set of broken houses would lead to minimizing the set of finally broken houses (In case of multiple answers, return the smallest index)
Description
In the neighbourhood of Iceland, there are a total of n houses. House i and House j are connected to each other if there exists a road from house i to house j. In this neighbourhood, if a robber breaks into a house i, he/she can also break into any house j that has a road from House i (i.e. house i and house j are connected through a road). A robber will continue breaking into houses until he/she can no more break into the remaining houses in the manner specified. There are some initial number of houses that have been broken by a robber and let M denote the final number of houses that will be broke by the robber. In this neighbourhood, there is a man by the name John who has the special ability to remove exactly one house from the initial set of broken houses. Help John to identify the house, which when removed from the list of initial broken houses, would minimize the value M.
It is to be noted that the house that was removed from the initial set of broken houses might still get broken by the robbers at a later point of time due to breaking of the houses connected by a road to it.
The road connectivity of the houses can be considered as an n*n adjaceny matrix graph called road, where the ith house is directly connected to the jth house if road[i][j]==1.
Input: Adjaceny matrix graph denoting road connectivity, and set of initial broken houses Output: The index of house(0-indexed) which when removed from initial set of broken houses would lead to minimizing the set of finally broken houses (In case of multiple answers, return the smallest index)
Example
Input: road= [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1] Output: 0
Constraints
Details
Directory Structure
Create a directory called JohnAndIceland under the Algorithms folder and add your code file there by naming it as JohnAndIceland.cpp
Note