Islands
The random map generator in the popular game Heroes of Might and Magic III creates islands where heroes are initially placed. These islands can vary in size. We define the "coefficient of unfairness" as the ratio of the area of the largest island to the area of the smallest island. Your task is to calculate this coefficient.
The map is represented as a rectangle of size N×M, where each cell contains either the digit 0 (representing water) or the digit 1 (representing land). An island is defined as the largest connected group of cells containing ones, meaning:
From any cell in the group A, you can reach any other cell in A by moving only through adjacent cells in A (sharing a side).
Adding any other cell containing 1 to A would break this connectivity condition.
Input
The first line of the input contains the integers N and M, which specify the dimensions of the map (1 ≤ N, M ≤ 1000). The map itself follows, consisting of M rows, each containing N numbers (0 or 1), separated by spaces.
Output
Output the coefficient of unfairness, formatted to 5 decimal places. If there are no islands on the map, output 0.