Problem Z
Economical Coverage

Providing wireless network coverage for a large office can
be tricky. In this problem you are asked to set up wireless
network coverage for an entire office floor plan. The floor
plan can be viewed as an
However, some issues arise. If neither of the two offices
incident to a corridor has a router, the corridor would have
weak signal. If both of the two offices incident to a corridor
have a router, the corridor would have conflicting signals that
would cause both routers to be inaccessible from the corridor.
(Unfortunately the routers available are pretty old models that
do not collaborate very well.) Consequently, for every corridor
that has either weak or conflicting signal, you must
additionally install a cellular hub, which provides separate
wireless service (that uses cellular network and is independent
of the routers). Each cellular hub is sold for
Find the minimum total cost to set up a wireless network that covers every corridor.
Input
The first line of the input has three integers
Output
Output the minimum total cost (in dollars) to provide a wireless network that covers every corridor.
Sample Input 1 | Sample Output 1 |
---|---|
2 3 4 10 1 3 0 1 20 |
9 |
Sample Input 2 | Sample Output 2 |
---|---|
2 3 100 10 1 10 10 1 10 |
21 |
Sample Input 3 | Sample Output 3 |
---|---|
2 2 1 10 10 10 10 |
4 |