A big international retailer is setting up shop in India and plans to open stores in N towns (3 ≤ N ≤ 1000), denoted by 1, 2, . . . , N.
There are direct routes connecting M pairs among these towns. The company decides to build warehouses to ensure that for any town X, there will be a warehouse located either in X or in an immediately neighboring town of X.
I need to find the minimum number of warehouses the company has to build.
Example : If we have N=10 towns and 7 routes between :
1 2
2 4
2 5
3 6
8 6
9 7
10 7
Here answer will be 3. Help me device an algorithm to do this problem.
Use Algorithm to find the number of connected components in a graph. The number of components in the graph will show how many warehouses are needed.So, that every places is reachable.