#K67207. Minimum Roads in a Grid
Minimum Roads in a Grid
Minimum Roads in a Grid
You are given an n x m grid representing intersections. To ensure that every intersection is reachable from every other, roads must be built to connect them. In graph theory, a connected graph with k nodes must have at least k - 1 edges.
Since there are n × m intersections, the minimum number of roads required is given by the formula:
$$n \times m - 1$$
For example, if n = 3
and m = 4
, the minimum number of roads required is 11
.
inputFormat
The input consists of two integers n
and m
separated by whitespace (spaces or newline). Here n
is the number of rows and m
is the number of columns of the grid.
outputFormat
Output a single integer representing the minimum number of roads required to connect all the intersections in the grid.
## sample1 1
0
</p>