Strategic Warehouse placements

1.3

25 votes
Algorithms, Open, Approved, Easy
Problem

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.

Write a program to find the minimum number of warehouses the company has to build.

[Input]:
Input will be given in the following format
N M
S1 E1 (Start Pt and End Pt of a direct route)
S2 E2
S3 E3
....
SM EM
Each route is bidirectional
No combination of towns will be repeated.

[Output]:
Output should be in a file in the following format
Wx - Minimum # of warehouses

*Problem provided by JDA

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?