WebClub-NITK / Hacktoberfest-2k21

Repository for Hacktoberfest-2k21

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

John and Iceland

SaishMendke opened this issue · comments

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

  • 2 <= n (Number of houses) <= 300
  • road[i][j] is 0 or 1.
  • road[i][j] == road[j][i]
  • road[i][i] == 1
  • 1 <= initial.length <= n
  • 0 <= initial[i] <= n - 1
  • All the integers in initial are unique.

Details

  • Technical Specifications: C, C++, Python
  • Type of issue: Single
  • Time Limit: 24 hours after the issue is assigned

Directory Structure

Create a directory called JohnAndIceland under the Algorithms folder and add your code file there by naming it as JohnAndIceland.cpp

Note

  1. Please claim the issue first by commenting here before starting to work on it.
  2. Once you are done with the task and have created a Pull Request, please tag @SaishMendke to request a review.