WC '17 Contest 4 S1 - Wakandan Sabotage
View as PDFWoburn Challenge 2017-18 Round 4 - Senior Division

The Infinity War has begun! Black Panther is well aware of the importance of rallying his supporters together to help defend Earth from the evil Thanos, so he's working on unifying the Wakandan army. Unbeknownst to him, however, Loki has formed a secret alliance with Thanos and is planning on sabotaging Black Panther's efforts.
The nation of Wakanda consists of  cities 
,
arranged in a grid with 
 rows and 
 columns. In each of
the 
 columns of the grid, there are 
 vertical roads connecting
pairs of vertically-adjacent cities. Additionally, in the bottom-most
and top-most rows only, there are 
 horizontal roads connecting
pairs of horizontally-adjacent cities. As such, there are 
roads in total throughout Wakanda. Each road is exactly 
 km long.
For example, if  and 
, the network of cities and roads
looks as follows:
Loki has the explosive resources to destroy  
roads of his choice. He'd hate for any of his explosives to
go to waste, so he'll destroy exactly 
 roads, no fewer.
Upon realizing that some roads have been destroyed, Black Panther will
still do his best to assemble the Wakandan army together. He'll ask
soldiers to travel amongst various cities which are still connected by
the remaining roads. Overall, the amount of time required for this
mobilization will depend on a single factor – the maximum shortest
distance (along undestroyed roads) between any pair of cities which are
still reachable from one another at all. In other words, if 
is equal to the shortest distance between cities 
 and 
 if they're
connected by roads (or is equal to 
 if they're not connected), then the
value of importance is 
 over all pairs of cities 
.
For example, if Loki were to destroy the two roads indicated in red
below, then the maximum shortest path between any pair of connected
cities would be  km long (for example, between the two cities marked in
green, along the roads indicated in blue).
Naturally, Loki is interested in selecting a set of  roads to destroy
such that this value is maximized. Help him determine the maximum
possible shortest distance between any pair of connected cities which
his sabotage can result in.
Subtasks
In test cases worth  of the points, 
.
Input Specification
The first and only line of input consists of three space-separated
integers, , 
, and 
.
Output Specification
Output a single integer, the maximum achievable shortest distance between any pair of cities which are still connected (in km).
Sample Input
2 4 4
Sample Output
6
Sample Explanation
Loki may choose to destroy the four roads indicated in red below. The
shortest path between the pair of cities marked in green would then be 
km long (consisting of the roads indicated in blue).
Comments